Recently in learning Python, idle bored to try to write this small script, although there are many shortcomings, but still a lot of harvest.
The functionality of the script:
① Traverse all the drive characters on the local computer and record the names;
② loops through all the pictures under the drive letter (of course, you can traverse different types of files depending on your needs) and download them.
Source code (please contact me if there is a shortage, thank you):
1#Coding=utf-82ImportOS3ImportShutil4 5#return to current working directory6 Beforedir =OS.GETCWD ()7 8defdir (to):9 picture = ["jpg","PNG"]10#traverse directory for all files, folders11 forRoot,dirs,filesinchOs.walk (To):12 forDirNameinchdirs:13#Recursive14dir (dirname)15 forFilenameinchFiles:16#returns the full path of the file+ Path =Os.path.join (root,filename)18#returns the size of a fileSize =os.path.getsize (path)20if((filename[-3:]inchPicture andFILENAME[0]! ="$") andSize < 2097152):21stshutil.copy (Path,beforedir)22 23#Traverse all drive letter names24 forIinchRange (65,91):Dirvename = Chr (i) +':'26ifOs.path.isdir (dirvename):27ifDirvename! ="C:":28PrintDirvenameDir (dirvename)
Python iterates through all the images under the drive letter and copies them down