python moving multiple files from one folder to the other based on text characters in file name -


I am quite new to Python . I am searching for the shutil module and can move things in general. My question revolves around:

Imagine a scenario in which there are hundreds of files in your export folder. While all the files are different, 13 of them are for specific vendors I run through the export file Want to create a script going to, evaluates each filename, captures all the apple files and puts them in apple folders, Intel files, and Puts them in the Intel folder. Any knowledge will be greatly appreciated.

I was trying to keep wildcard in the code shutil , but I had no luck.

thanks,

jt

The easiest solution I can think about:

  importil import os source = '/ path / to / source_folder' dest1 = '/ path / to / apple_folder' dest2 = '/ path / to / intel_folder' files = .listdir (source) for f in the OS file: if (f.startswith ("Apple") or f.startswith ("apple")): shutil.move (f, dest1) elif (f.startswith ("Intel ") Or F.startswith (" intel "): shutil.move (f, dest2)  

Do of the destination folders is required.

< / Div>

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -