Spaces:
Runtime error
Runtime error
File size: 996 Bytes
3c10631 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# Python 3 code to rename multiple
# files in a directory or defect_path
# importing os module
import os
# Function to rename multiple files
def main():
defect_path = "../pics/Defect"
ndefect_path = "../pics/nDefect"
for count, filename in enumerate(os.listdir(defect_path)):
dst = f"{str(count)}.jpg"
src =f"{defect_path}/{filename}" # defect_pathname/filename, if .py file is outside defect_path
dst =f"{defect_path}/{dst}"
# rename() function will
# rename all the files
os.rename(src, dst)
for count, filename in enumerate(os.listdir(ndefect_path)):
dst = f"{str(count)}.jpg"
src =f"{ndefect_path}/{filename}" # defect_pathname/filename, if .py file is outside defect_path
dst =f"{ndefect_path}/{dst}"
# rename() function will
# rename all the files
os.rename(src, dst)
# Driver Code
if __name__ == '__main__':
# Calling main() function
main() |