I think I have managed to get this resolved.Wrote a Pyhon script to rename files, but it deletes them instead of renaming them. What am I doing wrong here? I have figured out the issue with renaming. Can someone tell me why the below if statement is failing now to pull only the files that start with the word "New"?
#! /usr/bin/python
import os
import datetime
import glob
now = datetime.datetime.now()
#store date in string variable
dateStr = str(now.strftime('%Y%m%d-'))
src = r"C:\Users\username\Downloads"
for file in glob.glob(os.path.join(src, '*.txt')):
#Grab the basename
fileName = os.path.basename(file)
newName = src + "\\" + dateStr + fileName
#THIS if statement does not work
#if fileName.startswith("New"):
os.rename(file, newName)
print(newName)
Can anyone advise why the above if-statement does not work?