Questions tagged [file-exists]

A "FileExists" method provides a mechanism to determine if a specified path/file exists.

Overview

FileExist methods, which are available in most languages, typically have a path/filename parameter and return a Boolean value, indicating whether the file exists.

Implementations

The following links provide reference to the method descriptions for various languages:

579 questions
6149
votes
44 answers

How do I check whether a file exists without exceptions?

How do I check whether a file exists or not, without using the try statement?
spence91
  • 67,587
  • 8
  • 25
  • 19
895
votes
17 answers

How do I check if a file exists in Java?

How can I check whether a file exists, before opening it for reading in Java (the equivalent of Perl's -e $filename)? The only similar question on SO deals with writing the file and was thus answered using FileWriter which is obviously not…
DVK
  • 119,765
  • 29
  • 201
  • 317
130
votes
8 answers

Deleting a file in VBA

Using VBA, how can I: test whether a file exists, and if so, delete it?
inglesp
  • 3,171
  • 9
  • 28
  • 30
111
votes
4 answers

How to detect if a specific file exists in Vimscript?

I'm looking for an elegant way in Vimscript to check if a file exists in the current directory. I came up with the code below but I'm not sure if that's the most elegant solution (I'll set a Vim option if the file exists). Is there any way of not…
stefanB
  • 69,149
  • 26
  • 113
  • 140
80
votes
5 answers

How to check whether file exists in Qt in c++

How do I check whether a file exists in a given path or not in Qt? My current code is below: QFile Fout("/Users/Hans/Desktop/result.txt"); if(!Fout.exists()) { eh.handleError(8); } else { // ...... } But when I run the code it is not…
user1322915
  • 1,111
  • 2
  • 12
  • 9
74
votes
15 answers

Check if a file exists with Lua

How can I check if a file exists using Lua?
Yoni
  • 779
  • 1
  • 5
  • 8
73
votes
4 answers

CMake check that a local file exists

In my CMake script I want to see if I have a file on my system, and if it is there do something with it, otherwise do something with a default file. Here is the code: find_file( ${project_name}_${customer}_config …
Ferenc Deak
  • 30,889
  • 14
  • 82
  • 151
72
votes
5 answers

Portable way to check if directory exists [Windows/Linux, C]

I would like to check if a given directory exists. I know how to do this on Windows: BOOL DirectoryExists(LPCTSTR szPath) { DWORD dwAttrib = GetFileAttributes(szPath); return (dwAttrib != INVALID_FILE_ATTRIBUTES && (dwAttrib &…
ivy
  • 1,255
  • 3
  • 14
  • 20
58
votes
8 answers

How to check if a file exists from a url

I need to check if a particular file exists on a remote server. Using is_file() and file_exists() doesn't work. Any ideas how to do this quickly and easily?
David
  • 14,182
  • 34
  • 96
  • 150
58
votes
6 answers

Check if file exists on remote server using its URL

How can I check in Java if a file exists on a remote server (served by HTTP), having its URL? I don't want to download the file, just check its existence.
Rui
  • 5,700
  • 9
  • 36
  • 55
57
votes
6 answers

check if file exists in php

if (!(file_exists(http://mysite.com/images/thumbnail_1286954822.jpg))) { $filefound = '0'; } why won't this work?
anonymous
  • 599
  • 1
  • 4
  • 5
45
votes
8 answers

VBA check if file exists

I have this code. It is supposed to check if a file exists and open it if it does. It does work if the file exists, and if it doesn't, however, whenever I leave the textbox blank and click the submit button, it fails. What I want, if the textbox is…
Josephine Bautista
  • 525
  • 2
  • 7
  • 8
41
votes
7 answers

PHP's file_exists() will not work for me?

For some reason this PHP code below will not work, I can not figure it out. It is very strange, file_exists does not seem to see that the image does exist, I have checked to make sure a good file path is being inserted into the file_exists function…
JasonDavis
  • 45,100
  • 92
  • 294
  • 508
38
votes
20 answers

file_exists() is too slow in PHP. Can anyone suggest a faster alternative?

When displaying images on our website, we check if the file exists with a call to file_exists(). We fall back to a dummy image if the file was missing. However, profiling has shown that this is the slowest part of generating our pages with…
Rik Heywood
  • 13,368
  • 9
  • 56
  • 77
34
votes
2 answers

PHP check file exists without knowing the extension

I need to check if a file exists but I don't know the extension. IE I would like to do: if(file_exists('./uploads/filename')): // do something endif; Of course that wont work as it has no extension. the extension will be either jpg, jpeg, png,…
Lee
  • 17,158
  • 23
  • 71
  • 97
1
2 3
38 39