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
36
votes
4 answers

Check if a directory contains a file with a given extension

I need to check the current directory and see if a file with an extension exists. My setup will (usually) only have one file with this extension. I need to check if that file exists, and if it does, run a command. However, it runs the else multiple…
Jacob Birkett
  • 1,927
  • 3
  • 24
  • 49
36
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
  • 20,034
  • 23
  • 75
  • 102
33
votes
2 answers

If file exists in folder read it else skip the processing part

I am reading in several *.csv, where the names and paths are determined at runtime. However sometimes there are files with do not exist. For this file I need kind of exception handling. Currently I am reading in my files with: companyFileName…
user2051347
  • 1,609
  • 4
  • 23
  • 34
32
votes
3 answers

.htaccess url-rewrite if file not exists

I must do a little trick for a site! The idea is: if a file for a required url exists then I go to that url, doing nothing more; if a file for a required url not exists, I must go to a file.php and than do something, but NOT changing the…
Kiavor
  • 476
  • 1
  • 7
  • 14
30
votes
3 answers

C# File.Exists returns false, file does exist

Using VS 15, C# with .Net 4.5.2 The computer is on an AD network, with the ad name "AD". This problem happens with AD normal-user rights, AD admin rights, and local admin rights. It doesn't matter what rights the program gets, the same problem…
HoverCatz
  • 65
  • 1
  • 5
  • 19
29
votes
4 answers

file_exists() or is_readable()

Which one should you use when you want to include a PHP file? if(file_exists($file) require "$file"; or if(is_readable($file) require "$file"; ?
Co za asy...
  • 291
  • 1
  • 3
  • 3
28
votes
3 answers

Check if a file exists before calling openFileInput

To read a file in Android from your app's private storage area you use the functionopenFileInput(). My question is, is there a way to check if this file exists before calling this function? The function can throw a FileNotFoundException, but I…
Pieces
  • 2,256
  • 5
  • 25
  • 39
28
votes
2 answers

Makefile - Make dependency only if file doesn't exist

Like the title says, I would like to make a dependency only if a certain file does not exist, NOT every time it updates. I have a root directory (the one with the makefile) and in it a sub-directory called "example". In my root directory are four .h…
Daniel
  • 1,920
  • 4
  • 17
  • 35
27
votes
12 answers

Verify if file exists or not in C#

I am working on an application. That application should get the resume from the users, so that I need a code to verify whether a file exists or not. I'm using ASP.NET / C#.
suresh
27
votes
3 answers

PHP Rename File name if Exists Append Number to End

I'm trying to rename the file name of an image when it's uploaded if it exists, say if my file name is test.jpg and it already exists I want to rename it as test1.jpg and then test2.jpg and so on. With the code I've written its changing my file name…
user2201765
  • 1,017
  • 6
  • 18
  • 21
25
votes
3 answers

Check if a file Exists async?

I wish there was a File.ExistsAsync() I have: bool exists = await Task.Run(() => File.Exists(fileName)); Using a thread for this feels like an antipattern. Is there a cleaner way?
Johan Larsson
  • 17,112
  • 9
  • 74
  • 88
24
votes
3 answers

checking if file exists in a specific directory

I am trying to check for a specific file in a given directory. I don't want the code but I want to fix the one I have. The only difference in this question, is that I look for files with an extension .MOD. I have the code ready:- public static int…
gkris
  • 1,209
  • 3
  • 17
  • 44
21
votes
6 answers

Case sensitive Directory.Exists / File.Exists

Is there a way to have a case sensitive Directory.Exists / File.Existssince Directory.Exists(folderPath) and Directory.Exists(folderPath.ToLower()) both return true? Most of the time it doesn't matter but I'm using a macro which seems not to work…
theknut
  • 2,533
  • 5
  • 26
  • 41
20
votes
3 answers

Python, subprocess, call(), check_call and returncode to find if a command exists

I've figured out how to use call() to get my python script to run a command: import subprocess mycommandline = ['lumberjack', '-sleep all night', '-work all day'] subprocess.call(mycommandline) This works but there's a problem, what if users don't…
Dave Brunker
  • 1,559
  • 5
  • 15
  • 23
18
votes
2 answers

Why does 'File.exists' return true, even though 'Files.exists' in the NIO 'Files' class returns false

I am trying to determine if a file exists in a network folder: // File name is "\\QWERTY\folder\dir\A123456.TXT" Path path = Paths.get("\\\\QWERTY\\folder\\dir\\A123456.TXT") Using NIO Files: Files.exists(path) == false Using…
The Coordinator
  • 13,007
  • 11
  • 44
  • 73
1
2
3
40 41