File tree 3 files changed +34
-0
lines changed
3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## Check if file/directory exists or not
2
+ - - - - - - -
3
+ # Aim
4
+ To find if a file exists on the system with the specified name
5
+
6
+ # To run
7
+ ``` python check.py ``` </br >
8
+ Enter the PATH of file/directory where it is to be searched</br >
9
+ Enter the name of the file</br >
10
+
11
+ # Example
12
+
13
+ ![ alt text] ( https://github.com/TaniaMalhotra/hacking-tools-scripts/blob/check-file-exists/Python/check-file-exists/Screenshot%20(587).png )
Original file line number Diff line number Diff line change
1
+ import os
2
+
3
+ # Taking the input path from the user
4
+ PATH = input ('Enter the path where you would wish to search the file or directory' )
5
+
6
+ # Asking user to input file name
7
+ file_name = input ('Enter the name of file or directory' )
8
+
9
+ # making the complete PATH by concatenating filename to path
10
+ Full_path = PATH + "/" + file_name
11
+
12
+ # Using os.path as it checks for both file and directory
13
+ print (os .path .exists (Full_path ))
14
+
15
+ # If path exists, then file also exitss
16
+ if (os .path .exists (Full_path )):
17
+ print ("The file or directory you are searching for exists in the given path" )
18
+
19
+ # if path os incorrect, that means no such file exits
20
+ else :
21
+ print ("The file or directory you are searching for does not exist in the given path" )
You can’t perform that action at this time.
0 commit comments