Every line of 'python move file 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.
15 def 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)
15 def 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)
32 def move_file(file_name, new_name): 33 34 print("Moving File '{}' to '{}'".format(file_name, new_name)) 35 36 # Try to rename the file 37 try: 38 os.rename(file_name, new_name) 39 except OSError as e: 40 print("Error moving file") 41 print(e)
130 def moveFile(src, dst, srcFolder): 131 srcSize = os.path.getsize(src) 132 if (safeCopy): 133 with file(src, 'rb') as fsrc: 134 with file(dst, 'w+b') as fdst: 135 shutil.copyfileobj(fsrc, fdst, 10485760) 136 shutil.copystat(src, dst) 137 else: 138 shutil.move(src, dst) 139 try: 140 with open(dst): pass 141 if os.path.exists(dst): 142 if srcSize == os.path.getsize(dst): 143 if os.path.dirname(src) == sourcePath: 144 return "\t==> Not removing parent folder because it is the sourcePath root directory" 145 else: 146 shutil.rmtree(parentfolderpath) 147 return "\tRemoved " + sourcePath + "/" + srcFolder 148 else: 149 return "\t==> Destination file size does not match the original file size\n==> An error may have occurred in the file move operation" 150 else: 151 return "\tFile move operation failed" 152 except IOError: 153 return "\tFile move operation failed"
9 def install_file(source_filename, dest_filename): 10 # do not overwrite network configuration if it exists already 11 # https://github.com/evilsocket/pwnagotchi/issues/483 12 if dest_filename.startswith('/etc/network/interfaces.d/') and os.path.exists(dest_filename): 13 print("%s exists, skipping ..." % dest_filename) 14 return 15 16 print("installing %s to %s ..." % (source_filename, dest_filename)) 17 try: 18 dest_folder = os.path.dirname(dest_filename) 19 if not os.path.isdir(dest_folder): 20 os.makedirs(dest_folder) 21 22 shutil.copyfile(source_filename, dest_filename) 23 except Exception as e: 24 print("error installing %s: %s" % (source_filename, e))
75 def move(self, source_file): 76 """ 77 It is important that 'move' is used rather than opening a stream to the 78 absolute path directly. 79 The remote destination could be 'scp' or another remote service. 80 Always using move allows for this abstraction at a later date 81 """ 82 self._create_folders_if_needed() 83 shutil.move(source_file, self.absolute)
464 def move_file(src, dest): 465 """Move source file to destination. 466 467 Overwrites dest. 468 469 Args: 470 src: str or path-like. source file 471 dest: str or path-like. destination file 472 473 Returns: 474 None. 475 476 Raises: 477 FileNotFoundError: out path parent doesn't exist. 478 OSError: if any IO operations go wrong. 479 480 """ 481 try: 482 os.replace(src, dest) 483 except Exception as ex_replace: 484 logger.error("error moving file %s to " 485 "%s. %s", src, dest, ex_replace) 486 raise
63 @staticmethod 64 def move_file(origpath, newpath): 65 origpath = os.path.abspath(origpath) 66 newpath = os.path.abspath(newpath) 67 shutil.move(origpath,newpath) 68 return newpath
52 def smart_move(source_path, dest_path): 53 _smart_move_or_copy(io.move, source_path, dest_path)
70 def move(self, dest): 71 os.rename(self.getSelected()[0], dest) 72 self.cd('.') 73 self.updateListing(self.pattern)