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:

606 questions
7012
votes
40 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
  • 77,143
  • 9
  • 27
  • 19
976
votes
19 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
  • 126,886
  • 32
  • 213
  • 327
135
votes
9 answers

Deleting a file in VBA

Using VBA, how can I: test whether a file exists, and if so, delete it?
inglesp
  • 3,299
  • 9
  • 32
  • 30
124
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
  • 77,323
  • 27
  • 116
  • 141
90
votes
6 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,445
  • 3
  • 15
  • 20
87
votes
17 answers

Check if a file exists with Lua

How can I check if a file exists using Lua?
Yoni
  • 909
  • 1
  • 7
  • 8
86
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
  • 34,348
  • 17
  • 99
  • 167
83
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,211
  • 2
  • 13
  • 10
63
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
  • 16,246
  • 34
  • 103
  • 162
63
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,900
  • 10
  • 38
  • 56
61
votes
7 answers

check if url exists in php

if (!(file_exists(http://example.com/images/thumbnail_1286954822.jpg))) { $filefound = '0'; } why won't this work?
anonymous
  • 639
  • 1
  • 5
  • 5
51
votes
10 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
  • 585
  • 2
  • 7
  • 8
50
votes
13 answers

How to check if file exists in Google Cloud Storage?

I have a script where I want to check if a file exists in a bucket and if it doesn't then create one. I tried using os.path.exists(file_path) where file_path = "/gs/testbucket", but I got a file not found error. I know that I can use the…
Tanvir Shaikh
  • 651
  • 2
  • 7
  • 10
47
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
  • 48,204
  • 100
  • 318
  • 537
44
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,816
  • 9
  • 61
  • 81
1
2 3
40 41