Created
August 28, 2020 11:16
-
-
Save Schnabulator/37c136ef4a0f1ff7d4775374c8f4efaf to your computer and use it in GitHub Desktop.
move this file into a directory from which you want all files with a specific ending get moved to another ending.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os.path | |
from os import listdir | |
from os.path import isfile, join | |
mypath="./" | |
targetdir=mypath+"./" | |
sourceending="php" | |
targetending="jpg" | |
dirs = [f for f in listdir(mypath) if not isfile(join(mypath, f))] | |
# print(dirs) | |
for d in dirs: | |
onlyfiles = [f for f in listdir(d) if isfile(join(d, f))] | |
# print(onlyfiles) | |
for i in onlyfiles: | |
# print(d+i) | |
tmp = i.split(".") | |
if len(tmp)>1 and tmp[1]==sourceending: | |
# print("rename from {} to {}".format(d+"/"+i,d+"/"+tmp[0]+".jpg")) | |
os.rename(d+"/"+i,d+"/"+tmp[0]+targetending) | |
print("rename from {} to {}".format(d+"/"+i,d+"/"+tmp[0]+targetending)) | |
# print("Moved {}".format(i)) | |
else: | |
print("Didnt handle ",i) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment