473,395 Members | 1,335 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,395 software developers and data experts.

An ideas why I am getting an error about files not existing when running this code?

Expand|Select|Wrap|Line Numbers
  1.  
  2. import shutil, sys, time, os
  3. src = 'c:/users/wca36050/temp1'
  4. dst = 'c:/users/wca36050/temp2'
  5. now = time.time()
  6. for f in os.listdir(src):
  7.     if os.stat(f).st_mtime < now - 7 * 86400:
  8.         if os.path.isfile(f):
  9.             shutil.move(f, dst)
  10.  
  11.  
Error: "WindowsError: [Error 2] The system cannot find the file specified: 'pic.jpg'"
Jul 26 '10 #1

✓ answered by bvdet

Buddy,

os.listdir() returns a list of the names of the file objects found in directory src (as in pic.jpg). os.stat(f) and os.path.isfile(f) expect the full path (as in c:/users/wca36050/temp1.pic.jpg). How else would the interpreter find the file?

2 1342
bvdet
2,851 Expert Mod 2GB
Buddy,

os.listdir() returns a list of the names of the file objects found in directory src (as in pic.jpg). os.stat(f) and os.path.isfile(f) expect the full path (as in c:/users/wca36050/temp1.pic.jpg). How else would the interpreter find the file?
Jul 26 '10 #2
@bvdet
That did it! Thanks! This is all new to me.

Expand|Select|Wrap|Line Numbers
  1.  
  2. for f in os.listdir(src):
  3.     if os.stat(src + f).st_mtime < now - 7 * 86400:
  4.         if os.path.isfile(src + f):
  5.             shutil.move(src + f, dst)
  6.  
  7.  
Jul 26 '10 #3

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

Similar topics

11
by: mikey_boy | last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP script with makes a simple connection to a mysql database called firstdb and just pulls back the results and displays on the...
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...
4
by: Al Williams | last post by:
Hi, I have error handling in place throughout my application. I also start the application wrapped in error handling code to catch any unexpected exceptions (i.e. exceptions that occur where I...
1
by: Rob R. Ainscough | last post by:
Can someone tell me how to debug a Windows Install problem? I've created the installer project from home PC, transfered the installer project to my work PC, build the project on my work PC, but...
7
by: iclinux | last post by:
Environment: WinXP SP2 + Python 2.4.2, with SOAPpy-0.11.6.zip, fpconst-0.7.2.zip, and PyXML-0.8.4.win32-py2.4.exe installed. Problem: I'm reading DiveIntoPython these days. When running code...
12
by: ishtar2020 | last post by:
Hi everybody I've been writing my very first application in Python and everything is running smoothly, except for a strange problem that pops up every once in a while. I'm sure is the kind of...
0
by: Leon | last post by:
I keep geting this error in the IE when trying to run the scrept below from an ASP page. Can any one help please. Error Type: Provider (0x80040E37) Table does not exist. /gal.asp, line 43
5
by: Dan Fulbright | last post by:
I'm trying to install PHP 5.2.2 on Windows, but I keep getting errors when running go-pear.bat: mmap cache can't open phar://go-pear.phar/index.php mmap cache can't open...
1
by: cmdolcet69 | last post by:
In the below code exact line If _graphicScreenShots(intloop) = "Summary" Then....... I get an error message Overload resolution failed because no Public '=' can be called with these arguments:...
7
by: surferj | last post by:
Hello, I am trying to run a macro in that was created in an earlier version of access but getting an error message when i try to run it in 2007. The error occurs on the DoCmd.RunMacro...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.