python - window error: [Error 3] The system cannot find the path specified: '.prank/*.* is shown -


my prankheader.py

import os  def removenumber(str):     no_digit = []      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 directory     files in os.listdir("./prank"):         # 2. if file has number, delete.         newfile = removenumber(files)         # 3. make list of char string         newfile = ''.join(newfile)         os.rename(files, newfile)      os.chdir(saved_file) 

and prank.py

import prankheader prankheader.renamefiles() 

both files in folder c:/users/myname/desktop/localserver/prank, , filder has folder, prank, contains pictures.

when tried implement program showed me "window error: [error 3] system cannot find path specified: '.prank/.'

is there knows why have error?

if change following line

for files in os.listdir("./prank"): 

to

for files in os.listdir("."): 

it should work. running program directory prank.

os.chdir("./prank") 

so enter directory prank/prank. in directory

os.listdir("./prank"): 

so it's looking directory prank/prank/prank won't find. os.listdir("."): listing files in current directory (which prank/prank)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -