Versioning File Name Using Python
Basically when I download a file, it should check whether the file exists or not. If not exits rename the file with the version-0 else if exists rename the file with the next itera
Solution 1:
Use glob to check for the file in your target directory:
I havent been able to test this code, consider it as pseudocode for now. But this should do the job once you integrate the method properly into your program.
import glob
currentVersion = glob.glob(yourFileName)
if currentVersion == []: #checks if file exists
download and saveAs version-0 #saves as original if doesnt existelse:
download and saveAs (fileName+(list(currentVersion[0])[-1] + 1) #if exists, gets the existing version number, and saves it as that number plus one
Post a Comment for "Versioning File Name Using Python"