473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Why am I getting this error?

I am attempting to write a script that will take a directory as an argument then go through said directory and rename files with a given extension (in this case .jpg)

here is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. import os
  2. fileDir=os.listdir("c:\\Users\\Nathan\\Desktop\\Cell Pics\\")
  3. count = 1
  4. for fn in fileDir:
  5.  
  6.     if fn[-4:] == '.jpg':
  7.         os.rename(fn,'%03i.jpg' % count)
  8.         count += 1
  9.  
now, when I replace the directory above with '.' and drop the script into the directory I want to affect it will do its job perfectly. However when I have the directory put into the parameter of os.listdir and attempt to run it I get the following error:
Expand|Select|Wrap|Line Numbers
  1. Traceback (most recent call last):
  2.   File "C:/Python27/test2.py", line 7, in <module>
  3.     os.rename(fn,'%03i' % count)
  4. WindowsError: [Error 2] The system cannot find the file specified
  5.  
What am I doing wrong?

I am using windows atm but this script is for UNIX. (if that matters let me know) I am pretty new to scripting and python (first week ever programming) so please be descriptive if at all possible!

thanks in advance!
Oct 8 '10 #1
1 1137
bvdet
2,851 Expert Mod 2GB
Join the path and the file name.
Expand|Select|Wrap|Line Numbers
  1. os.path.join("c:\\Users\\Nathan\\Desktop\\Cell Pics\\", fn)
Oct 8 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: IMS.Rushikesh | last post by:
Hi Friends, My work is stuck up because of this unresolvable and unbelievable Error. I'm trying to Serialize my Class object using XmlSerialization. And at below line, I m getting "error File...
8
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported...
5
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse...
1
by: jonny | last post by:
Went from using Visual Web Develop express to Visual Studio 2005 and getting error when trying to open project. Error message: "One or more projects in the solution could not be loaded for the...
21
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
2
by: sony.m.2007 | last post by:
Hi, When i try to set a value for a session variable I'm getting a object refence not set error I tried two methods as below HttpContext.Current.Session.Add("AppStartTime", DateTime.Now);...
4
by: sumit kale | last post by:
Hi, Can somebody help me resolve my problem ? I am getting error when calculating total using unbound textfiled in subform. I have a main form called purchase_register_master and a subform...
12
by: tvnaidu | last post by:
Trying to mount windows folder on Linux machine, getting this error. I have a folder called "CheckIn" on windows, I made that folder as Network sharing. ON lInux, I tried to access that folder by...
2
by: bandy | last post by:
Hi there sorry If I posted this thread under wrong head. When I am trying to run my site I am getting error as Internal Server Error, but when I refresh page , i get result properly. I don't...
1
by: NareshN | last post by:
Hi, I am getting error because of this line in stored procedure.How to enclose string value. Count(Case When Totalhours<='25:0' Then EmpNo end) as Less. 25:0 is varchar datatype so i am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.