Oct-06-2020, 06:41 AM
So Hey! I Have A Problem Not Homework
Problem: I Have Many Font Files(Zip Download From GOogle Zip) And I Want to Move Them Only Ttf And Otf Files
SO I have Done THis Approach
Here Are The Errors
Problem: I Have Many Font Files(Zip Download From GOogle Zip) And I Want to Move Them Only Ttf And Otf Files
SO I have Done THis Approach
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#import libraries from pathlib import Path import os from datetime import datetime from collections import namedtuple import pandas as pd import shutil #Create A File nametuple file = namedtuple( 'File' , 'name path size modified_date' ) #Create Empty list files = [] #File Path p = Path(r "C:\Users\DELL\Desktop\Python_Projects\fonts-master\fonts-master\ofl" ) #iterate though path objects find all that end with .ttf and .otf save to list for item in p.glob( '**/*' ): if item.suffix in [ '.ttf' , '.otf' ]: name = item.name path = Path.resolve(item).parent size = item.stat().st_size modified = datetime.fromtimestamp(item.stat().st_mtime) files.append( file (name, path, size, modified)) #print(os.path.exists(str(path))) #ERROR BELOW shutil.move(path,r 'C:\Users\DELL\Desktop\Python_Projects\fonts-master\All Fonts' ) #Create Dataframe from list df = pd.DataFrame(files) #Export To Csv df.to_csv( 'ttf_and_otf.csv' ,index = False ) |
Error:Traceback (most recent call last):
File "C:\Users\DELL\Desktop\Python_Projects\fonts-master\fonts-master\lel.py", line 30, in <module>
shutil.move(path,r'C:\Users\DELL\Desktop\Python_Projects\fonts-master\All Fonts')
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 784, in move
real_dst = os.path.join(dst, _basename(src))
File "C:\Users\DELL\AppData\Local\Programs\Python\Python38\lib\shutil.py", line 747, in _basename
return os.path.basename(path.rstrip(sep))
AttributeError: 'WindowsPath' object has no attribute 'rstrip'