├── README.md └── File Manager.py /README.md: -------------------------------------------------------------------------------- 1 | # python-file-manager 2 | 3 | [![forthebadge made-with-python](http://ForTheBadge.com/images/badges/made-with-python.svg)](https://www.python.org/) 4 | 5 | [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com) 6 | 7 | Hi! **python-file-manager** is a file manager (for windows) based on *Python 3.7*. It was made by [Aman Binjola](www.github.com/binjolaaman10) as a personal project. With this python based file explorer you can view files, folders and perform actions on them. Actions such as moving them, deleting them (permanently or sending them to recycle bin). 8 | 9 | ## Modules Used: 10 | 11 | 1. send2trash 12 | 2. os 13 | 3. shutil 14 | 4. sys 15 | 16 | Python 3.7 or above is recommended for using this program. 17 | You need to install *send2trash* module first. You can do this by using the following command: 18 | 19 | > pip install send2trash 20 | 21 | **send2trash** is a python module that sends files/folders to Recycle Bin instead of permanently deleting it. 22 | 23 | ## Functions you can perform on files/folders 24 | 25 | 1. Delete files/folder permanently 26 | 2. Send files/folder to Recycle Bin 27 | 3. Directly open files from the manager 28 | 4. Expand folders 29 | 5. Move files/folders to another location 30 | 6. Copy files/folders to another location 31 | 32 | -------------------------------------------------------------------------------- /File Manager.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This is a python based file manager system 3 | for Microsoft Windows made by Aman Binjola 4 | as a personal project. 5 | 28-November-2019 6 | 7 | https://github.com/binjolaaman10/python-file-manager 8 | ''' 9 | 10 | #! python3 11 | 12 | import sys 13 | import os 14 | import shutil 15 | import send2trash 16 | 17 | print('Welcome to the python-file-manager\n') 18 | 19 | # Stores every drive connected on PC in a list. 20 | drives = [chr(x) + ':' for x in range(65, 90) if os.path.exists(chr(x) + ':')] 21 | 22 | # Lists each folder and file present in the current working directory 23 | def listDirectories(): 24 | listdir = os.listdir(os.getcwd()) 25 | for x in listdir: 26 | print(x) 27 | 28 | while True: 29 | print("1.Open files/folders \n2.Rename \n3.Move and Paste \n4.Copy and Paste \n5.Delete\n") 30 | result = input("Choose one of the following: ") 31 | 32 | if result == '1': 33 | # Home Screen 34 | print('\nQuick Acess:\n1. Documents\n2. Videos\n3. Pictures\n4. Downloads\n') 35 | 36 | print('Drives: ') 37 | for x in range(len(drives)): 38 | print(str(5 + x) + '. ' + drives[x]) 39 | 40 | while True: 41 | inp = input("\nEnter your Choice: ") 42 | 43 | if inp == '1': 44 | path = 'C:\\Users\\$USERNAME\\Documents' 45 | os.chdir(os.path.expandvars(path)) 46 | break 47 | 48 | elif inp == '2': 49 | path = 'C:\\Users\\$USERNAME\\Videos' 50 | os.chdir(os.path.expandvars(path)) 51 | break 52 | 53 | elif inp == '3': 54 | path = 'C:\\Users\\$USERNAME\\Pictures' 55 | os.chdir(os.path.expandvars(path)) 56 | break 57 | 58 | elif inp == '4': 59 | path = 'C:\\Users\\$USERNAME\\Downloads' 60 | os.chdir(os.path.expandvars(path)) 61 | break 62 | 63 | elif inp in drives: 64 | os.chdir(inp + '\\') 65 | break 66 | 67 | else: 68 | print('Error\nEnter a correct input / drive name.\n') 69 | 70 | while True: 71 | 72 | listDirectories() 73 | 74 | print('\n\nType "exitManager" to exit from file manager.') 75 | print('Type "backManager" to go up one directory.') 76 | res = input('\nChoose a file/folder: ') 77 | print('\n') 78 | 79 | if res in os.listdir(os.getcwd()): 80 | if os.path.isfile(res): 81 | os.system('"' + res + '"') 82 | else: 83 | os.chdir(res) 84 | 85 | elif res == 'exitManager': # Exit command to exit from loop 86 | sys.exit(0) 87 | 88 | elif res == 'backManager': # Back command to go up one directory 89 | os.chdir('..') 90 | 91 | else: 92 | print('No file/folder exist of this name.') 93 | 94 | if result == '2': 95 | print("You chose to rename") 96 | print('Drives: ') 97 | for x in range(len(drives)): 98 | print(str(1 + x) + '. ' + drives[x]) 99 | 100 | while True: 101 | inp = input("\nEnter your Choice: ") 102 | 103 | if inp in drives: 104 | os.chdir(inp + '\\') 105 | break 106 | else: 107 | print('Error\nEnter a correct drive name.\n') 108 | 109 | while True: 110 | 111 | listDirectories() 112 | 113 | print('\n\nType "exitManager" to exit from file manager.') 114 | print('Type "backManager" to go up one directory.') 115 | print('Type "renameManager" to rename this directory') 116 | 117 | res = input('\nChoose a file to rename: ') 118 | print('\n') 119 | 120 | if res in os.listdir(os.getcwd()): 121 | if os.path.isfile(res): 122 | 123 | new_name = input("Enter a new name: ") 124 | ogDir = res 125 | newDir = os.getcwd() + '\\' + new_name 126 | shutil.move(ogDir, newDir) 127 | else: 128 | os.chdir(res) 129 | 130 | elif res == 'exitManager': # Exit command to exit from loop 131 | sys.exit(0) 132 | 133 | elif res == 'backManager': # Back command to go up one directory 134 | os.chdir('..') 135 | 136 | elif res == 'renameManager': # Rename command to delete one directory 137 | 138 | new_name = input("Enter a new name: ") 139 | ogDir = os.getcwd() 140 | os.chdir('..') 141 | newDir = os.getcwd() + '\\' + new_name 142 | shutil.move(ogDir, newDir) 143 | 144 | else: 145 | print('No file/folder exist of this name.') 146 | 147 | if result == '3': 148 | print("You chose to move") 149 | print('Drives: ') 150 | for x in range(len(drives)): 151 | print(str(1 + x) + '. ' + drives[x]) 152 | 153 | while True: 154 | inp = input("\nEnter your Choice: ") 155 | 156 | if inp in drives: 157 | os.chdir(inp + '\\') 158 | break 159 | else: 160 | print('Error\nEnter a correct drive name.\n') 161 | 162 | while True: 163 | 164 | listDirectories() 165 | 166 | print('\n\nType "exitManager" to exit from file manager.') 167 | print('Type "backManager" to go up one directory.') 168 | print('Type "cutManager" to move this directory') 169 | 170 | res = input('\nChoose a file to move: ') 171 | print('\n') 172 | 173 | if res in os.listdir(os.getcwd()): 174 | 175 | if os.path.isfile(res): 176 | og_path = os.getcwd() + "\\" + res 177 | print("\nMove " + res + " to a desired location.") 178 | 179 | while True: 180 | for x in range(len(drives)): 181 | print(str(1 + x) + '. ' + drives[x]) 182 | 183 | inp2 = input("\nEnter your Choice: ") 184 | 185 | if inp2 in drives: 186 | os.chdir(inp2 + '\\') 187 | break 188 | else: 189 | print('Error\nEnter a correct drive name.\n') 190 | 191 | while True: 192 | listDirectories() 193 | 194 | print('Type "pasteManager" to paste this file in current directory') 195 | 196 | res2 = input('\nChoose a file to move: ') 197 | print('\n') 198 | 199 | if res2 in os.listdir(os.getcwd()): 200 | if os.path.isfile(res): 201 | print("You can't choose a file.\nPlease choose a folder.") 202 | else: 203 | os.chdir(res2) 204 | 205 | elif res2 == 'pasteManager': 206 | shutil.move(og_path, os.getcwd()) 207 | break 208 | 209 | else: 210 | os.chdir(res) 211 | 212 | 213 | elif res == 'exitManager': # Exit command to exit from loop 214 | sys.exit(0) 215 | 216 | elif res == 'backManager': # Back command to go up one directory 217 | os.chdir('..') 218 | 219 | elif res == 'cutManager': 220 | og_path = os.getcwd() 221 | 222 | print("Moving the current directory") 223 | while True: 224 | for x in range(len(drives)): 225 | print(str(1 + x) + '. ' + drives[x]) 226 | 227 | inp2 = input("\nEnter your Choice: ") 228 | 229 | if inp2 in drives: 230 | os.chdir(inp2 + '\\') 231 | break 232 | else: 233 | print('Error\nEnter a correct drive name.\n') 234 | 235 | while True: 236 | listDirectories() 237 | 238 | print('\nType "pasteManager" to paste this folder in current directory') 239 | 240 | res2 = input('\nChoose a folder to open: ') 241 | print('\n') 242 | 243 | if res2 in os.listdir(os.getcwd()): 244 | if os.path.isfile(res): 245 | print("You can't choose a file.\nPlease choose a folder.") 246 | else: 247 | os.chdir(res2) 248 | 249 | elif res2 == 'pasteManager': 250 | shutil.move(og_path, os.getcwd()) 251 | break 252 | 253 | else: 254 | print('No file/folder exist of this name.') 255 | 256 | if result == '4': 257 | print("You chose to copy") 258 | print('Drives: ') 259 | for x in range(len(drives)): 260 | print(str(1 + x) + '. ' + drives[x]) 261 | 262 | while True: 263 | inp = input("\nEnter your Choice: ") 264 | 265 | if inp in drives: 266 | os.chdir(inp + '\\') 267 | break 268 | else: 269 | print('Error\nEnter a correct drive name.\n') 270 | 271 | while True: 272 | 273 | listDirectories() 274 | 275 | print('\n\nType "exitManager" to exit from file manager.') 276 | print('Type "backManager" to go up one directory.') 277 | print('Type "copyManager" to copy this directory') 278 | 279 | res = input('\nChoose a file to copy: ') 280 | print('\n') 281 | 282 | if res in os.listdir(os.getcwd()): 283 | 284 | if os.path.isfile(res): 285 | og_path = os.getcwd() + "\\" + res 286 | print("Move " + res + " to a desired location.") 287 | 288 | while True: 289 | for x in range(len(drives)): 290 | print(str(1 + x) + '. ' + drives[x]) 291 | 292 | inp2 = input("\nEnter your Choice: ") 293 | 294 | if inp2 in drives: 295 | os.chdir(inp2 + '\\') 296 | break 297 | else: 298 | print('Error\nEnter a correct drive name.\n') 299 | 300 | while True: 301 | listDirectories() 302 | 303 | print('Type "pasteManager" to copy this file in current directory') 304 | 305 | res2 = input('\nChoose a file to move: ') 306 | print('\n') 307 | 308 | if res2 in os.listdir(os.getcwd()): 309 | if os.path.isfile(res): 310 | print("You can't choose a file.\nPlease choose a folder.") 311 | else: 312 | os.chdir(res2) 313 | 314 | elif res2 == 'pasteManager': 315 | shutil.copy(og_path, os.getcwd()) 316 | break 317 | 318 | else: 319 | os.chdir(res) 320 | 321 | 322 | elif res == 'exitManager': # Exit command to exit from loop 323 | sys.exit(0) 324 | 325 | elif res == 'backManager': # Back command to go up one directory 326 | os.chdir('..') 327 | 328 | elif res == 'copyManager': 329 | og_path = os.getcwd() 330 | 331 | print("Copying the current directory") 332 | while True: 333 | for x in range(len(drives)): 334 | print(str(1 + x) + '. ' + drives[x]) 335 | 336 | inp2 = input("\nEnter your Choice: ") 337 | 338 | if inp2 in drives: 339 | os.chdir(inp2 + '\\') 340 | break 341 | else: 342 | print('Error\nEnter a correct drive name.\n') 343 | 344 | while True: 345 | listDirectories() 346 | 347 | print('\nType "pasteManager" to copy this file in current directory') 348 | 349 | res2 = input('\nChoose a folder to open: ') 350 | print('\n') 351 | 352 | if res2 in os.listdir(os.getcwd()): 353 | if os.path.isfile(res): 354 | print("You can't choose a file.\nPlease choose a folder.") 355 | else: 356 | os.chdir(res2) 357 | 358 | elif res2 == 'pasteManager': 359 | print(og_path) 360 | folder_name = og_path.split('\\')[-1] 361 | folder_directory = os.getcwd() + '\\' + folder_name 362 | shutil.copytree(og_path, folder_directory) 363 | break 364 | 365 | else: 366 | print('No file/folder exist of this name.') 367 | 368 | if result == '5': 369 | while True: 370 | 371 | # Options to delete files/folders to permanently or otherwise 372 | print('\n1. Permanently \n2. Recycle Bin') 373 | query = input('Would you like to permanently delete or send to Recycle Bin?: ') 374 | 375 | if query == '1': 376 | print('You chose to permanently delete files/folders.\n') 377 | print('Drives: ') 378 | for x in range(len(drives)): 379 | print(str(1 + x) + '. ' + drives[x]) 380 | 381 | while True: 382 | inp = input("\nEnter your Choice: ") 383 | 384 | if inp in drives: 385 | os.chdir(inp + '\\') 386 | break 387 | else: 388 | print('Error\nEnter a correct drive name.\n') 389 | 390 | while True: 391 | 392 | listDirectories() 393 | 394 | print('\n\nType "exitManager" to exit from file manager.') 395 | print('Type "backManager" to go up one directory.') 396 | print('Type "deleteManager" to permanently delete this directory') 397 | 398 | res = input('\nChoose a file to delete: ') 399 | print('\n') 400 | 401 | if res in os.listdir(os.getcwd()): 402 | if os.path.isfile(res): 403 | 404 | # Warning to prevent unnecessary deletion 405 | print('Are you sure you want to permanently delete this file? (YES/NO)') 406 | ans = input('Yes or No: ') 407 | if ans.lower() == 'yes' or 'y': 408 | os.unlink(res) 409 | else: 410 | os.chdir(res) 411 | 412 | elif res == 'exitManager': # Exit command to exit from loop 413 | sys.exit(0) 414 | 415 | elif res == 'backManager': # Back command to go up one directory 416 | os.chdir('..') 417 | 418 | elif res == 'deleteManager': # Delete command to delete one directory 419 | 420 | # Warning to prevent unnecessary deletion 421 | print('Are you sure you want to permanently delete this folder? (YES/NO)') 422 | ans = input('Yes or No: ') 423 | 424 | if ans.lower() == 'yes' or 'y': 425 | path = os.getcwd() 426 | os.chdir('..') 427 | shutil.rmtree(path) 428 | 429 | else: 430 | print('No file/folder exist of this name.') 431 | 432 | elif query == '2': 433 | print('You chose to temporarily delete files/folders.') 434 | print('Drives: ') 435 | for x in range(len(drives)): 436 | print(str(1 + x) + '. ' + drives[x]) 437 | 438 | while True: 439 | inp = input("\nEnter your Choice: ") 440 | 441 | if inp in drives: 442 | os.chdir(inp + '\\') 443 | break 444 | else: 445 | print('Error\nEnter a correct drive name.\n') 446 | 447 | while True: 448 | 449 | listDirectories() 450 | 451 | print('\n\nType "exitManager" to exit from file manager.') 452 | print('Type "backManager" to go up one directory.') 453 | print('Type "deleteManager" to send this directory to recycle bin') 454 | 455 | res = input('\nChoose a file to delete: ') 456 | print('\n') 457 | 458 | if res in os.listdir(os.getcwd()): 459 | if os.path.isfile(res): 460 | 461 | # Warning to prevent unnecessary deletion 462 | print('Are you sure you want to send this folder to recycle bin? (YES/NO)') 463 | ans = input('Yes or No: ') 464 | if ans.lower() == 'yes' or 'y': 465 | send2trash.send2trash(res) 466 | else: 467 | os.chdir(res) 468 | 469 | elif res == 'exitManager': # Exit command to exit from loop 470 | sys.exit(0) 471 | 472 | elif res == 'backManager': # Back command to go up one directory 473 | os.chdir('..') 474 | 475 | elif res == 'deleteManager': # Delete command to delete one directory 476 | 477 | # Warning to prevent unnecessary deletion 478 | print('Are you sure you want to send this folder to recycle bin? (YES/NO)') 479 | ans = input('Yes or No: ') 480 | 481 | if ans.lower() == 'yes' or 'y': 482 | path = os.getcwd() 483 | os.chdir('..') 484 | send2trash.send2trash(path) 485 | 486 | else: 487 | print('No file/folder exist of this name.') 488 | 489 | else: 490 | print('You chose wrong number') 491 | --------------------------------------------------------------------------------