Skip to content

Commit f7c0002

Browse files
authored
Merge pull request #360 from TaniaMalhotra/check-file-exists
Script to check if file exists python
2 parents 39a1091 + 6e5e37d commit f7c0002

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

Python/check-file-exists/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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)
133 KB
Loading

Python/check-file-exists/check.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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")

0 commit comments

Comments
 (0)