1
我PrankHeader.py窗口错误:错误3]系统找不到指定的路径:” .prank /*.*显示
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)
而且我Prank.py
import PrankHeader
PrankHeader.renameFiles()
这两个文件都在C:/ Users/Myname/Desktop/LocalServer/Prank文件夹中,并且文件夹中有包含图片的文件夹Prank。
当我试图执行程序这表明我 “窗口中的错误:错误3]系统找不到指定的路径:‘.prank/’
有没有谁知道我为什么有一个错误?
你做一个os.chdir(“Prankt)目录恶作剧,然后在该目录中,你做一个os.listdir(”./恶作剧“),但目录恶作剧目录中没有目录恶作剧,只需做一个listdir(”。“)然后它应该工作 – erik
实际上,恶作剧目录中有一个恶作剧目录第一个恶作剧是程序(用dirs和py),第二个恶作剧是包含一堆图片的文件夹,我想改变他们的名字。 –