shutil

python 3.x shutil.copy FileNotFoundError

自闭症网瘾萝莉.ら 提交于 2021-02-19 08:47:07
问题 system Windows 8.1 Python 3.4 Repeatedly get FileNotFound Errno2 , attempting to copy all files in a directory. import os import shutil source = os.listdir("C:\\Users\\Chess\\events\\") for file in source : shutil.copy(file, "E:\\events\\") yields FileNotFoundError : [Errno2] No such file or directory 'aerofl03.pgn'. Although 'aerofl03.pgn' is first in the source list ['aerofl03.pgn', ...] . Same result if a line is added: for file in source : if file.endswith('.pgn') : shutil.copy(file, "E:\

Cannot copy file from a remote machine using shutil

末鹿安然 提交于 2021-02-08 19:44:00
问题 I need to copy a file from a remote machine. The code is something like this import shutil shutil.copyfile('//XXX.XXX.XXX.XXX/home/Shares Folder/file.txt','/home/file.txt') the location of the file is a shared folder but everytime I run this it gives me this error File "", line 1, in ? File "usr/lib/python2.4/shutil.py", line 47, in copyfile frsc = open (src,'rb') IOError: [Errno 2] No such file or directory : '//XXX.XXX.XXX.XXX/home/Shares Folder/file.txt' Please take note that I'm running

Cannot copy file from a remote machine using shutil

倖福魔咒の 提交于 2021-02-08 19:41:23
问题 I need to copy a file from a remote machine. The code is something like this import shutil shutil.copyfile('//XXX.XXX.XXX.XXX/home/Shares Folder/file.txt','/home/file.txt') the location of the file is a shared folder but everytime I run this it gives me this error File "", line 1, in ? File "usr/lib/python2.4/shutil.py", line 47, in copyfile frsc = open (src,'rb') IOError: [Errno 2] No such file or directory : '//XXX.XXX.XXX.XXX/home/Shares Folder/file.txt' Please take note that I'm running

Regular expression in Python Shutil integer range to move files

南楼画角 提交于 2020-07-16 09:42:24
问题 I have a folder with 12500 pictures. The filenames contain the numbers, so it looks like: 0.jpg 1.jpg 2.jpg 3.jpg . . .12499.jpg Now I want to move the files. Files with range 0-7999 should be copied to the first folder. Files 8000-9999 should be copied to the second folder and files with range 10000-12499 should be copied to the third folder. First, I thought I could easily use [0-7999].jpg for the first folder, [8000-9999].jpg for the second and [10000-12499].jpg for the third. However,

How to delete permanently from mounted Drive folder?

岁酱吖の 提交于 2020-06-01 07:45:48
问题 I wrote a script to upload my models and training examples to Google Drive after every iteration in case of crashes or anything that stops the notebook from running, which looks something like this: drive_path = 'drive/My Drive/Colab Notebooks/models/' if path.exists(drive_path): shutil.rmtree(drive_path) shutil.copytree('models', drive_path) Whenever I check my Google Drive, a few GBs is taken up by dozens of deleted models folder in the Trash, which I have to manually delete them. The only

Overwrite directory with shutil.rmtree and os.mkdir sometimes gives 'Access is denied' error

那年仲夏 提交于 2020-05-14 18:23:08
问题 My code: if os.path.exists(myDir): shutil.rmtree(myDir) os.mkdir(myDir) Problem: It always work if myDir does not exist. If myDir exists, sometimes it throws error, sometimes it works. Error log: os.mkdir(myDir) PermissionError: [WinError 5] Access is denied: 'myDir' My guess: when I call os.mkdir, sometimes shutil.rmtree hasn't finished execution/ hasn't released the permission for the directory. Hence, the error. Is there any way to ensure complete execution of shutil.rmtree before calling

Flask send_file is sending old file instead of newest

大憨熊 提交于 2020-05-12 18:51:51
问题 I have a flask app where using one Flask route the server creates a csv file and saves it to the server. Using a generated button on the client page, another Flask route is triggered to get the most recent file, move it to a tmp folder and send that file to the user using send_file . Right now, when I run the process the first time and download the file, all works as expected. However, the second time I run the process, it serves me the old CSV instead of the newly generated one. This