shutil

how to move files in directories in group of 3

how to move files in directories in group of 3 Question: I have 60 files and 20 folders in same directory. I want to move first three files to the first folder, next three files to another folder and so on. Basically move 60 files in group of three into 20 folders. I made a …

Total answers: 1

How to skip permission error while deleting all files from a folder

How to skip permission error while deleting all files from a folder Question: I am working on a python script in which i am trying to delete all the files which are there within the given folder , though few errors like below are acting as a road block due to which the code is …

Total answers: 2

Alternative for python shutils.copytree?

Alternative for python shutils.copytree? Question: recently i built a tool, which is able to copy files and directories to a selected location. I used the shutil.copy function for copying files and the shutil.copytree function for copying directories. It all worked fine until i stumbled upon the following problem: shutil.copytree function takes two arguments: src and …

Total answers: 1

How to copy only non-duplicate files whilst maintaining folder structure?

How to copy only non-duplicate files whilst maintaining folder structure? Question: I am trying to find duplicates between two folders and copy only unique image files to the ‘dest’ folder. I can copy all the non-dupes using the code below, however it doesn’t maintain the source directory structure. I think OS.walk returns 3 tuples, but …

Total answers: 3

python elegant way to create folders and move files

python elegant way to create folders and move files Question: Currently, I have more than 30 .xlsx files in my source folder. All these 30 files are from different regions in APAC which has keywords such as IND, KOR, ASN etc. My objective is to do the below a) create separate folders for each region …

Total answers: 1

copying only 10gb of files from a folder that say contains 100gb using python

copying only 10gb of files from a folder that say contains 100gb using python Question: i have this script that copies all files with the file extension txt which scans all the files in the folder and then copies them to another folder. The thing is most of the time there is over 100GB of …

Total answers: 1

How to copy first n images from a directory to another directory?

How to copy first n images from a directory to another directory? Question: I need to copy the first 1400 images from one directory to another. The code I’ve seen: fnames = [‘{}.app_res_model.tiff’.format{i} for i in range(1400)] for fname in fnames: src = os.path.join(dataset_dir, fname) dst = os.path.join(train_dir_input, fname) shutil.copyfile(src, dst) As my images are …

Total answers: 1

Print number of occurrences of any items in a list in paths

Print number of occurrences of any items in a list in paths Question: I am using os.walk to identify paths in a generic source directory (SRC) that contain any strings in my_list: SRC = ‘/User/dir_1/’ my_list = ["dog", "cat", "mouse", "bird"] for dirpath, dirnames, filenames in os.walk(SRC): for folders in dirnames: for x in my_list: …

Total answers: 1