-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFileManager.py
More file actions
104 lines (85 loc) · 3.11 KB
/
FileManager.py
File metadata and controls
104 lines (85 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
import shutil
import subprocess
def moveFile(filepath):
if filepath:
print("File found at: " + filepath)
print("---" * 30)
parent_folder = input("What is the parent of this folder: ")
folder_name = input("Enter folder name to move file into: ")
destination_path = os.path.join(os.path.expanduser("~"), parent_folder, folder_name)
print("Destination path: " + destination_path)
confirm = input("Are you sure you want to do this? (Y/N): ").lower()
if confirm == "y":
try:
os.makedirs(destination_path, exist_ok=True)
shutil.move(filepath, os.path.join(destination_path, os.path.basename(filepath)))
print("File moved successfully!")
except Exception as e:
print("Error: " + str(e))
else:
print("File not moved.")
else:
print("File not found.")
def openFile(found_file=None):
if not found_file:
found_file = input("Enter the file name to search and open: ")
file_found = False
for dirpath, dirnames, filenames in os.walk(os.path.expanduser("~")): # Update the base directory to search for files
for file in filenames:
if found_file in file:
found_file = os.path.join(dirpath, file)
file_found = True
break
if file_found:
break
if file_found:
print("File found at:", found_file)
subprocess.run(['open', found_file]) # Open the file with default macOS application
else:
print("File not found.")
def searchComputer():
filename = input("Enter the file name to search: ")
filetype = input("Enter the file type: ")
found_file = None
for dirpath, dirnames, filenames in os.walk('/'): # Update the base directory to search for files
for file in filenames:
if filename in file and file.endswith("." + filetype):
found_file = os.path.join(dirpath, file)
break
if found_file:
break
if found_file:
print("File found at:", found_file)
return found_file
else:
print("File not found.")
return None
# Update the code to set the filepath variable before calling moveFile or openFile
def main():
global filepath
while True:
print("1. Move File")
print("2. Open File")
print("3. Search Computer")
print("4. Exit")
choice = input("Enter your choice (1/2/3/4): ")
print("---" * 30)
if choice == "1":
filepath = searchComputer()
moveFile(filepath)
filepath = ""
elif choice == "2":
filepath = searchComputer()
openFile(filepath)
filepath = ""
elif choice == "3":
filepath = searchComputer()
elif choice == "4":
print("Exiting...")
break
else:
print("Invalid choice. Please choose from 1, 2, 3, or 4.")
print("---" * 30)
if __name__ == "__main__":
main()