My PrankHeader.py
import os
def removeNumber(str):
no_digit = []
for char in str:
if not char.isdigit():
no_digit.append(char)
return no_digit
def renameFiles():
saved_file = os.getcwd()
os.chdir("./prank")
# 1. loop through files in the directory
for files in os.listdir("./prank"):
# 2. if the file has the number, delete.
newFile = removeNumber(files)
# 3. make the list of char to string
newFile = ''.join(newFile)
os.rename(files, newFile)
os.chdir(saved_file)
And my Prank.py
import PrankHeader
PrankHeader.renameFiles()
Both files are in the folder C:/Users/Myname/Desktop/LocalServer/Prank, and the filder has the folder, Prank, which contains the pictures.
When I tried to implement the program it showed me "window error: [Error 3] The system cannot find the path specified: '.prank/ . '
Is there anyone who knows why I have an error?
If you change the following line
for files in os.listdir("./prank"):
To
for files in os.listdir("."):
it should work. You are running the program from the directory Prank. Then you do a
os.chdir("./prank")
So you enter the directory Prank/Prank. In that directory you do a
os.listdir("./prank"):
so it's looking for the directory Prank/prank/prank which it won't find. But with os.listdir("."):
you are listing files in current directory (which is Prank/Prank)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.