![]() The following output will be appeared after running the above script. # Print the message if the file not exists Print ( "The %s is moved to the location, %s" % (source_path, new_location ) ) ![]() # Set the directory path where the file will be moved If the file does not exist, then an error message will be printed. The destination location will be printed after moving the file. If the file exists, the destination path of the file will be defined where the file will be moved. Path module is imported to use the exists() function for checking the given filename exists or not. The shutil module is imported in the script to use the move() function for moving the file. The way to move a file from one location to another location with the original name has shown in the following script. Example-1: Move the file with the original name ![]() These two methods can be used to move the file from one directory to another directory, as explained in this tutorial. Another way of moving file location by using rename() method that is defined in the os module. Move () is the most used method of Python to move the file from one directory to another directory defined in the shutil module. This task can be done by using Python script in multiple ways. Sometimes we require to move the file location from one path to another path for the programming purpose. The file is used to store data permanently.
0 Comments
Leave a Reply. |