Reputation: 380
Someone who I took over their position as data analyst has a program that searches for a "bad character" in a filename which they assigned in a variable to "~". This prints out "bad character in filename". It is printing out when checking a folder if a file exists there but I don't understand why. The program just looks for if the filestamp of the file being added was today, doesn't matter the name.
for filename in os.listdir(strSrcName): # llok through files in the directory of the second row in SQL table, SAT_Report_Status
mdate = datetime.datetime.fromtimestamp(os.stat(strSrcName + filename).st_ctime).strftime('%m/%d/%Y')
jdate = datetime.datetime.fromtimestamp(os.stat(strSrcName + filename).st_ctime).strftime('%Y/%j')
if filename.find(strFileName) >=0: # If number of files is 0 or more?
badchar = "~" # Not sure what this is for
if filename[0] in badchar:
print("Bad Char found in file name, skipping...")
else:
if mdate == fdate or jdate == juldate: # if the files timestamp == the current timestamp (now)
print(strFileName + " Found! Counting and Moving...")
Does this have any special meaning in Python? I don't even know what it means in general
Upvotes: 0
Views: 75
Reputation: 13858
To give a proper answer - "~"
doesn't really have a special meaning in Python as it's just a piece of str
object. The literal character ~
however is used in binary operation, but is not your concern at the moment.
As mentioned, your script seems to be looking for file names beginning with a ~
. This has to do with the OS - in Windows, files beginning with ~
denotes a temporary file, which your script seems to want to ignore (probably because the data is not meaningful to the script).
Upvotes: 1