![]() Refer to those in the same directory as our Python file. In this example, we have specified relative file paths for our source and destination. Variable stores the name of the directory in which we want to move our file. ![]() Variable stores the name of the file we want to move. We could do so using this code:įirst, we have imported the shutil library. ![]() Which we want to move into a directory called Let’s explore a few examples of how to use the shutil.move() function. But, the shutil method was designed specifically for moving files. If you specify a destination directory that does not exist, a new directory will be created. Relative file path refers to a location that is relative to the directory in which your Python program is being run (i.e. The file paths you specify can be either absolute or relative.Ībsolute file paths are complete paths that lead directly to a file (i.e. If your destination matches another file, the existing file will be overwritten. : The file path where you want to move your file.įunction returns the path of the file you have moved. : The file path of the file you want to move.
0 Comments
Leave a Reply. |