5 examples of 'python move files to another directory' in Python

Every line of 'python move files to another directory' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
15def move_file(source_folder, filename, destin_folder):
16 files = os.listdir(source_folder)
17 if filename in files:
18 shutil.move(source_folder+"/" + filename,destin_folder)

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

52def smart_move(source_path, dest_path):
53 _smart_move_or_copy(io.move, source_path, dest_path)
15def move_file(path, target_path):
16 target_dir = os.path.dirname(target_path)
17 if not os.path.exists(target_dir):
18 os.makedirs(target_dir)
19 shutil.move(path, target_path)
74def move_files(self,root,remaining_modules):
75 """
76 Goes through each path in the dictionary and moves it to "root/self.unused_directory/"
77 Once finished it prints out the total number of files moved.
78 """
79 try:
80 for key in remaining_modules:
81 os.rename(remaining_modules[key],root + "/" + self.unused_directory + "/" + key)
82 print "Moved %d files" % len(remaining_modules)
83 except OSError as err:
84 print("Unable to move files: {0}".format(err))
85 print("Target destination: " + self.unused_directory)
422def copy_files(src_dir, dst_dir, names):
423 os.makedirs(dst_dir, exist_ok=True)
424 rm_files(dst_dir)
425 for name in names:
426 src_path = os.path.join(src_dir, name)
427 dst_path = os.path.join(dst_dir, name)
428 shutil.copy(src=src_path, dst=dst_path)

Related snippets