shutil

Python multiprocess/multithreading to speed up file copying

巧了我就是萌 提交于 2019-12-19 04:05:52
问题 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 shutil to copy the files over sequentially and it is taking some time, so I'm trying to find the best way to opimize this. I've noticed some software I use effectively multi-threads reading files off of the network with huge gains in load times so I'd

Copying specific files to a new folder, while maintaining the original subdirectory tree

喜你入骨 提交于 2019-12-19 04:04:34
问题 I have a large directory with many subdirectories that I am trying to sort, I am trying to copy specific file types to a new folder, but I want to maintain the original subdirectories. def copyFile(src, dest): try: shutil.copy(src,dest) except shutil.Error as e: print('Error: %s' % e) except IOError as e: print('Error: %s' % s.strerror) for root, directories, files in os.walk(directory): for directoryname in directories: dirpath = os.path.join(root,directoryname) dir_paths.append(dirpath) dir

Permission denied doing os.mkdir(d) after running shutil.rmtree(d) in Python

 ̄綄美尐妖づ 提交于 2019-12-18 03:31:21
问题 Very often in the Windows 7 console if I run a python program twice very quickly that does if os.path.isdir(d): shutil.rmtree(d) if not os.path.exists(d): os.mkdir(d) where d is the name of a directory with many files, I get a "Permission denied" for the mkdir command. But if I run once, then wait some seconds, then run again I do not get such error. What is the problem here? 回答1: There are three things that come to mind: Windows itself delays some file operations in order to preserve

How do I copy an entire directory of files into an existing directory using Python?

心不动则不痛 提交于 2019-12-17 02:28:12
问题 Run the following code from a directory that contains a directory named bar (containing one or more files) and a directory named baz (also containing one or more files). Make sure there is not a directory named foo . import shutil shutil.copytree('bar', 'foo') shutil.copytree('baz', 'foo') It will fail with: $ python copytree_test.py Traceback (most recent call last): File "copytree_test.py", line 5, in <module> shutil.copytree('baz', 'foo') File "/System/Library/Frameworks/Python.framework

Delete a current directory based on If condition

泄露秘密 提交于 2019-12-13 02:58:09
问题 Following code counts number of image in each sub directory. how to delete a sub directory if images in sub-directory are more than 2. n13 is main directory => which have 300 sub-directories(1...300) => each sub-directory have images . output: Images:2, Directory:1 Images:3, Directory:2 Images:4, Directory:3 import os path='C:/n13/' def count_em(path): x = 0 for root, dirs, files in os.walk(path): files_count = (len(files)) x = x + 1 print("Images:",files_count,"Directory:",x) return files

Errno 2 using python shutil.py No such file or directory for file destination

橙三吉。 提交于 2019-12-12 14:04:54
问题 I am using the shutil python module to copy files and directories on a linux redhat machine. I wrote the following method, which takes in 2 params: src (the path of the file or dir that is being collected) and destination (the desired new path of where the collected log/dir is being pasted to). def copy(src, destination): if(os.path.exists(src)): if(os.path.isdir(src)): if(os.path.exists(destination)): shutil.copytree(src, destination+getTimeStamp()) else: shutil.copytree(src, destination)

-Python- Move All PDF Files in Folder to NewDirectory Based on Matching Names, Using Glob or Shutil

孤街醉人 提交于 2019-12-11 08:35:52
问题 I'm trying to write code that will move hundreds of PDF files from a :/Scans folder into another directory based on the matching each client's name. I'm not sure if I should be using Glob, or Shutil, or a combination of both. My working theory is that Glob should work for such a program, as the glob module "finds all the pathnames matching a specified pattern," and then use Shutil to physically move the files? Here is a breakdown of my file folders to give you a better idea of what I'm trying

Python - copying specific files from a list into a new folder

你。 提交于 2019-12-11 08:13:11
问题 I am trying to get my program to read a list of names from a file (say .txt), then search for those in a selected folder and copy and paste those files to another selected folder. My program runs without errors but does not do anything: Code - updated: import os, shutil from tkinter import filedialog from tkinter import * root = Tk() root.withdraw() filePath = filedialog.askopenfilename() folderPath = filedialog.askdirectory() destination = filedialog.askdirectory() filesToFind = [] with open

shutil.which() not finding programs without appending file extension

强颜欢笑 提交于 2019-12-11 07:26:38
问题 Trying to use shutil.which() to determine if git is installed. From the docs, I see which() on Windows should use PATHEXT to know which file extensions to append when searching. However the following occurs when using the interpreter: >>> import os >>> import shutil >>> os.getenv('PATHEXT') '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;' >>> shutil.which('git') >>> shutil.which('git.exe') 'C:\\Program Files\\Git\\cmd\\git.exe' This is in a virtual environment created using VirtualEnv

shutil.move IOError: [Errno 2] - When in loop [closed]

纵然是瞬间 提交于 2019-12-11 02:56:41
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . If I run shutil.move(file, dest) on its own it works fine, the problem I'm having is when I loop through, the loop works fine without the shutil.move.