So i have this code and I want to copy files that are created in only in "2022.02.01"
import os, glob, shutil, datetime
target_dir=/home/blabla
for source_dir in glob.iglob("/mnt/bla/bla/bla*/*bla*/bla/bla/*.bla.png"
d = "*.bla.png".datetime("2022,02,01")
if source_dir == d
shutil.copy(source_dir, target_dir)
but I get this error
Traceback (most recent call last):
File "s.py", line 33, in <module>
d= "*.bla.png".datetime("2022,02,01")
AtributeError: 'str' object has no attribute 'datetime'
Any suggestions how to fix that? It works fine until i add the date I want this script to print my files to my given direction
CodePudding user response:
You don't need the datetime module to make it work. Since all the dates have the same format, you can identify the files to copy with a simple string check,
import glob, shutil
target_dir='test'
target_date = '2022.02.01'
for source_dir in glob.iglob("bla*.txt"):
if target_date in source_dir:
shutil.copy(source_dir, target_dir)
