--Move files that meet the conditions -(Example) Set the condition to a file name that includes "today's date"
--File search pathlib
--Move shutil
import pathlib
import shutil
import datetime
#Today's date
yyyymmdd = datetime.date.today().strftime('%Y%m%d')
#Get the file name that matches the conditions from the source folder
#I want to receive it in the list, so cast it
p_tmp = list(pathlib.Path('Source folder').glob(f'{yyyymmdd}*.csv'))
'''Corrected the list to ↑
p_tmp = pathlib.Path('Source folder').glob(f'{yyyymmdd}*.csv')
p = [p for p in p_tmp]
'''
dest = 'Destination folder'
#Move file
for source in p_tmp:
shutil.move(str(source), dest)
--The file name picked up by pthlib
is returned by ** Generator **
-** Store in list ** and retrieve file names one by one with for statement
-↑ Although it was listed in the comprehension notation, it turned out that you can cast with ** `list``` ** without having to bother to do that. --** Convert the extracted file name with
str``` ** -** ``` Shutiful.move ([Move source], [Move destination]) Move file with
`**
Recommended Posts