About 272,000 results
Open links in new tab
  1. How do I move a file in Python? - Stack Overflow

    Jan 13, 2012 · In a nutshell, Python's shutil.move will raise an exception (but gnu-coreutils mv will not) when your destination is a directory and the directory already has a file with the same name as the source (again for more info see the link provided in the previous sentence). –

  2. Rename and move file with Python - Stack Overflow

    You should have the wanted directory to save the file in, and the new file name. You can do this for every file you run across in your loop. For example: # In Windows dest_dir = "tmp\\2" new_name = "bar.txt" current_file_name = "tmp\\1\\foo.txt" os.rename(current_file_name, os.path.join(dest_dir, new_name))

  3. Moving all files from one directory to another using Python

    Jan 24, 2017 · This should do the trick. Also read the documentation of the shutil module to choose the function that fits your needs (shutil.copy(), shutil.copy2(), shutil.copyfile() or shutil.move()).

  4. Python - Move and overwrite files and folders - Stack Overflow

    What I want to do is move the contents of 'src Directory' to 'Dst Directory' and overwrite any files that exist with the same name. So for example 'Src Directory\file.txt' needs to be moved to 'Dst Directory\' and overwrite the existing file.txt.

  5. How to move file from folder A to folder B in python?

    Oct 17, 2021 · You can try importing shutil and calling shutil.move(source,destination). The shutil module provides functions for moving files, as well as entire folders. Share

  6. Python moving files and directories from one folder to another

    Dec 18, 2014 · I would like to move in python files and directories in one directory to another directory with overwrite ability. I started with the following code: #moving files from progs path = tempfolder + 'progs/' for dirs,files in os.listdir(path): for f in files: shutil.move(os.path.join(path, f) , os.path.join(compteurfolder, f))

  7. How to move a file in a directory to another in python

    Dec 12, 2022 · use shutil.move method to move a file shutil.move(src, dst, copy_function=copy2) Recursively move a file or directory (src) to another location (dst) and return the destination. refer. source = 'path/to/file' destination = 'path/to/file' dest = shutil.move(source, destination, copy_function = shutil.copytree)

  8. python - How do I copy a file? - Stack Overflow

    Sep 23, 2008 · shutil has many methods you can use. One of which is: import shutil shutil.copyfile(src, dst) # 2nd option shutil.copy(src, dst) # dst can be a folder; use shutil.copy2() to preserve timestamp

  9. Moving files with python (Windows) - Stack Overflow

    Apr 8, 2014 · You can not move a file to another directory using rename, you can rename a file using move though. Move can replace an existing file (use /y), rename can't. You can both use slash or backslash, backslash needs to be escaped by using 2 backslashes where you need 1 and 4 backslashes where you need 2. Your function move needs a return.

  10. Moving specific file types with Python - Stack Overflow

    May 9, 2014 · Another option is using glob module, which let's you specify file mask and retrieve list of desired files. It should be as simple as

Refresh