shutil

Python (openpyxl) : Put data from one excel file to another (template file) & save it with another name while retaining the template

余生颓废 提交于 2019-12-05 02:04:49
问题 I have a template excel file named as template.xlsx which has a number of sheets. I would like to copy data from a seperate .csv file into the first sheet of template.xlsx (named as data ) and save the new file as result.xlsx while retaining the original template file. I want to paste the data starting from the second row in the data sheet of template.xlsx This is the code I have developed so far import pandas as pd from openpyxl.utils.dataframe import dataframe_to_rows import openpyxl from

Is python's shutil.copyfile() atomic?

杀马特。学长 韩版系。学妹 提交于 2019-12-05 01:55:47
I'm writing a python script that copies a file using shutil.copyfile() on Linux. During the copying, other processes may be trying to read the file. Is the following sufficient to ensure that an external process doesn't get a corrupted view of the file? os.unlink(dest) shutil.copyfile(src, dest) That is, is shutil.copyfile() atomic such that other processes cannot read the destination file until after the copy operation is complete? No, it seems to just loop, reading and writing 16KB at a time . For an atomic copy operation, you should copy the file to a different location on the same

Move and replace if same file name already existed in python

喜欢而已 提交于 2019-12-03 18:28:23
问题 Here is below code which will move and replace individual file import shutil import os src = 'scrFolder' dst = './dstFolder/' filelist = [] files = os.listdir( src ) for filename in files: filelist.append(filename) fullpath = src + '/' + filename shutil.move(fullpath, dst) If i execute same command and moving file which already existed in dst folder i am getting shutil.Error: Destination path './dstFolder/file.txt' already exists how to do move and replace if same file name already existed

Python (openpyxl) : Put data from one excel file to another (template file) & save it with another name while retaining the template

浪子不回头ぞ 提交于 2019-12-03 16:42:02
I have a template excel file named as template.xlsx which has a number of sheets. I would like to copy data from a seperate .csv file into the first sheet of template.xlsx (named as data ) and save the new file as result.xlsx while retaining the original template file. I want to paste the data starting from the second row in the data sheet of template.xlsx This is the code I have developed so far import pandas as pd from openpyxl.utils.dataframe import dataframe_to_rows import openpyxl from shutil import copyfile template_file = 'template.xlsx' # Has a header in row 1 already which needs to be

Python: copy long file path Shutil.copyfile

感情迁移 提交于 2019-12-02 07:14:55
I want to copy too long paths with python using shutil.copyfile. Now I read this Copy a file with a too long path to another directory in Python page to get the solution. I used: shutil.copyfile(r'\\\\?\\' + ErrFileName,testPath+"\\"+FilenameforCSV+"_lyrErrs"+timestrLyr+".csv") to copy the file but it gives me an error : [Errno 2] No such file or directory: '\\\\?\\C:\\... Can anyone please let me know how to incorporate longs paths with Shutil.copyfile, the method I used above should allow 32k characters inside a file path, but I cant even reach 1000 and it gives me this error. Since the \\?\

Stop shutil.make_archive adding archive to itself

亡梦爱人 提交于 2019-12-02 02:21:52
问题 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 dir. I tried shutil.make_archive but when I do this import shutil shutil.make_archive('App-1.0', 'zip', '.') from Release dir, I get 48 byte App-1.0.zip inside App-1.0.zip besides the App dir. That is it adds this unfinished archive to itself. Is there any way

How to match and move files into corresponding folders using Python

a 夏天 提交于 2019-12-02 02:16:29
问题 I am fairly new to programing and this is my first stab at creating a complex script using Python The purpose of the program I am creating is: to go through a list of files (360 files altogether in a single folder) extract 3 unique characters in the file name and create a folder based on the 3 characters (60 unique folders altogether) create a for loop which goes through the list of files in the source folder and moves it to its corresponding target folder. Example: file name: KPHI_SDUS81

Python recursive find files and move to one destination directory

懵懂的女人 提交于 2019-12-02 01:30:41
问题 The script should recursively go through the rootpath directory and find all files with *.mp4 extension. Print the list of files with the directory structure. Then move the files to the destDir directory. The problem I run into is when trying to move the files to the new directory. Only files in the rootPath directory will be moved to the new destination. Files in subdirectories under rootPath causes errors: /Volumes/VoigtKampff/Temp/TEST/level01_test.mp4 /Volumes/VoigtKampff/Temp/TEST

Python recursive find files and move to one destination directory

隐身守侯 提交于 2019-12-01 21:55:59
The script should recursively go through the rootpath directory and find all files with *.mp4 extension. Print the list of files with the directory structure. Then move the files to the destDir directory. The problem I run into is when trying to move the files to the new directory. Only files in the rootPath directory will be moved to the new destination. Files in subdirectories under rootPath causes errors: /Volumes/VoigtKampff/Temp/TEST/level01_test.mp4 /Volumes/VoigtKampff/Temp/TEST/Destination/2levelstest02.mp4 Traceback (most recent call last): File "/Volumes/HomeFolders/idmo04/Desktop

using shutil.copyfile I get a Python IOError: [Errno 13] Permission denied:

可紊 提交于 2019-12-01 16:13:39
I have some python code using shutil.copyfile: import os import shutil src='C:\Documents and Settings\user\Desktop\FilesPy' des='C:\Documents and Settings\user\Desktop\\tryPy\Output' x=os.listdir(src) a=os.path.join(src,x[1]) shutil.copyfile(a,des) print a It gives me an error: IOError: [Errno 13] Permission denied: 'C:\\Documents and Settings\\user\\Desktop\\tryPy\\Output' Why don't I have permission to copy the file? From the documentation of shutil.copyfile : Copy the contents (no metadata) of the file named src to a file named dst. dst must be the complete target file name; look at shutil