Skip to content
Advertisement

Tag: shutil

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

I am using os.walk to identify paths in a generic source directory (SRC) that contain any strings in my_list: And let’s say that print(source_path) gives the following: My goal is to shutil.move my source_path’s, but since, for example, moving /User/dir_1/bird_files/ and then trying to move /User/dir_1/bird_files/bird_a_files/ will result in a FileNotFound Error, I want to filter my source_path’s to include

Is there any method to compress ZIP files in python?

I have tried creating zip using zipfile and shutil. But, there was not visible file size compression in both the methods. zipfile shutil Is there any way to ensure file compression as well? Thanks. Answer You did zipfile.ZipFile docs state The compresslevel parameter controls the compression level to use when writing files to the archive. When using ZIP_STORED or ZIP_LZMA

Using random and shutil to move files in loop in python

I have a small problem. I am trying to move 20×500 images in 20 predefined folders. I can make this work with just 500 random images and I have identified the problem; I draw 500 random files, move them and then it tries doing it again but since it doesn’t update the random list, it fails when it reaches an

Lost files while tried to move files using python shutil.move

I had 120 files in my source folder which I need to move to a new directory (destination). The destination is made in the function I wrote, based on the string in the filename. For example, here is the function I used. In the function, I am creating the destination folders, based on the ID’s derived from the files list.

Advertisement