Questions tagged [shutil]

A Python module which contains a number of utility methods for file or directory operations, such as copying, moving, etc.

The Python shutil module offers a number of high-level operations on files and collections of files. In particular, functions are provided which support file copying and removal.

Documentation: https://docs.python.org/3.2/library/shutil.html

1181 questions
6
votes
2 answers

Stop shutil.make_archive adding archive to itself

I have App dir inside Release dir $ cd Release $ tree . `-- App |-- App.exe .......... and I am trying to create App-1.0.zip in the Release dir containg App with all its content. That is after unpacking App-1.0.zip I would get this App…
Alex P.
  • 3,697
  • 9
  • 45
  • 110
6
votes
1 answer

Move files in folders to a top-level directory

I am trying to complete a script for my work that cleans up their file organization system. The last part of my script needs to go inside all folders in a given directory, and move all files in every folder to the directory. For example: import…
Bkal05
  • 109
  • 2
  • 7
6
votes
5 answers

Python multiprocess/multithreading to speed up file copying

I have a program which copies large numbers of files from one location to another - I'm talking 100,000+ files (I'm copying 314g in image sequences at this moment). They're both on huge, VERY fast network storage RAID'd in the extreme. I'm using…
Spencer
  • 1,931
  • 1
  • 21
  • 44
6
votes
0 answers

shutil move raising Invalid cross-device link error

I am using Python 3.5. I am using shutil.move(src, dest) to move a file between 2 different file systems. As I understand cross-device link error is raised by OS because it can't create hard links across 2 different file systems, which is fine. But…
pranav3688
  • 694
  • 1
  • 11
  • 20
6
votes
3 answers

Is there a way to move many files quickly in Python?

I have a little script that moves files around in my photo collection, but it runs a bit slow. I think it's because I'm doing one file move at a time. I'm guessing I can speed this up if I do all file moves from one dir to another at the same time.…
allyourcode
  • 21,871
  • 18
  • 78
  • 106
6
votes
4 answers

What is difference between root and base directory?

I am trying to use shutils.py , make_archive function. here: https://docs.python.org/2/library/shutil.html#archiving-operations but I can't understand the difference between root_dir and base_dir. Here's a simple code using…
Heartagramir
  • 344
  • 1
  • 2
  • 9
6
votes
1 answer

PermissionError: [WinError 32] The process cannot access the file because it is being used by another process:

I'm trying to test my own version of antiweb, which can be found here. However, I am testing it with Pythons unittest module. Here is the code: import unittest from unittest.mock import patch from antiweb import main import sys import os import…
Phil
  • 91
  • 1
  • 8
6
votes
0 answers

Why does shutil.copy throw "OSError: [Errno 38] Function not implemented: '/media/some/path'"?

I have a relatively straight forward snippet which throws an error: import shutil abspath_to_source_file = '/media/moose/VFF1147/MAP_DATA/BACK/B0000040.DFT' target_dir =…
Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
6
votes
3 answers

Python copy or move files whose names are on a list in a text file

Can anyone tell me how to copy or move a batch of files to another directory or other directories. The name of the files are in a list that are in a text file. I'm working on a Windows system. The text file contains a list similar to…
user3346706
  • 69
  • 1
  • 3
6
votes
2 answers

Python shutil.copy fails on FAT file systems (Ubuntu)

Problem: Using shutil.copy() to copy a file to a FAT16 mounted filesystem in Linux fails (Python 2.7.x). The failure is shutil internal error and failing actually on shutil.chmod, which shutil.copy seems to execute. Shell chmod fails, too, as…
Hannu
  • 11,685
  • 4
  • 35
  • 51
6
votes
1 answer

wait for shutil.copyfile to finish

I want to copy a file then start writing the new file: shutil.copyfile("largefile","newlargefile") nwLrgFile=open("newlargefile",'a') nwLrgFile.write("hello\n") However, when I do the above hello will be written before the end of the file. What is…
a113nw
  • 1,312
  • 1
  • 16
  • 26
6
votes
3 answers

python shutil.copytree - ignore permissions

Python's shutil.copytree is not very flexible; what is the simplest way to add support for ignoring permissions while copying in copytree (without having to re-write its implementation)? Otherwise, copytree fails like this: (…)”[Errno 45] Operation…
Sridhar Ratnakumar
  • 81,433
  • 63
  • 146
  • 187
5
votes
1 answer

Difference between shutil.copy2(s,d) and shutil.move(s,d)

I have read the documentation provided for shutil.move and copy2. From my understanding move just calls the copy2 function, then calls the remove function, while copy2 calls copy then copystat. That all makes sense, except when I use them I find…
user880455
  • 53
  • 1
  • 4
5
votes
1 answer

PyLint raises 'misplaced-bare-raise' in error handler function for shutil.rmtree(...)

Context: I am using shutil.rmtree(delDir, ignore_errors = False, onerror = readOnlyErrorHandler) to delete a directory tree that holds readonly files: Annoyence: PyLint (inside VS Code) marks the raise command inside my readOnlyErrorHandler…
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
5
votes
0 answers

shutil.move can't move files between disk drives?

I am using shutil.move to move files from my downloads (C:) to a folder on a server (Z:). source_dir = "C:\\Users\\e1206433\\Downloads\\estadisticaEjecGlo*.csv" dest_dir1 = "Z:\\AN\Produban\Operations\Print Management\Misc\Luca\TEST 1" for file in…
Cappy
  • 61
  • 1
  • 6