Bracktus Bracktus - 8 months ago 259
Python Question

FileNotFoundError: [WinError 2] The system cannot find the file specified:

import os

def rename(directory):
for name in os.listdir(directory):

path = input("Enter the file path")

I want to rename every file in a certain directory so that it adds a 0 to the beginning of the file name, however when I try to run the code it comes up with this error:

(FileNotFoundError: [WinError 2] The system cannot find the file specified: '0.jpg' -> '00.jpg')

I'm sure that there is a file in there named 0.jpg and i'm not sure what the problem is.

Sorry if this is a stupid question i'm new to coding.


As written you're looking for a file named 0.jpg in the directory of the script itself. You want to be looking in the directory you pass in.

So instead do: