Greetings,
I am attempting to view all files in a directory and if those files
have not been modified within the last couple days I will remove them.
In order to do this I need to look at the file date modied and check
the date. I know how to look at each file name and I know how to remove
the file. I just can't figure out how to get access to the date last
modifed filed. Below is how I intend to access the file names in the
directory.
>>import os,time,sys cachedirector y="c:\\informat ica\\cache\\" v_filename_ar ray=os.listdir( cachedirectory) x_len=len(v_f ilename_array)
v_filename_arra y[0] = first file name
v_filename_arra y[1] - second file name
Thanks'
Rich 3 7178
I hope this sample code helps
def getfileinfo(fil ename):
print 'Filename : %s' % filename
stats = os.stat(filenam e)
size = stats[stat.ST_SIZE]
print 'File Size is %d bytes' % size
accessed = stats[stat.ST_ATIME]
modified = stats[stat.ST_MTIME]
print 'Last accessed: ' + time.ctime(acce ssed)
print 'Last modified: ' + time.ctime(modi fied)
Regards,
Praveen
On Oct 30, 8:00 am, RAMohrm...@adel phia.net wrote:
Greetings,
I am attempting to view all files in a directory and if those files
have not been modified within the last couple days I will remove them.
In order to do this I need to look at the file date modied and check
the date. I know how to look at each file name and I know how to remove
the file. I just can't figure out how to get access to the date last
modifed filed. Below is how I intend to access the file names in the
directory.
>import os,time,sys cachedirectory ="c:\\informati ca\\cache\\" v_filename_arr ay=os.listdir(c achedirectory) x_len=len(v_fi lename_array)v_ filename_array[0] = first file name
v_filename_arra y[1] - second file name
Thanks'
Rich
RA********@adel phia.net wrote:
Greetings,
I am attempting to view all files in a directory and if those files
have not been modified within the last couple days I will remove them.
In order to do this I need to look at the file date modied and check
the date. I know how to look at each file name and I know how to remove
the file. I just can't figure out how to get access to the date last
modifed filed.
For this you have some solutions.
1,
import os
import time
time.ctime(os.s tat(r"L:\MyDoc\ EBook\Python"). st_mtime)
2,
os.path.getmtim e()
3, in Win32
win32file.GetFi leTime
int = GetFileTime(han dle, creationTime , accessTime , writeTime ) RA********@adel phia.net wrote:
I am attempting to view all files in a directory and if those files
have not been modified within the last couple days I will remove them.
In order to do this I need to look at the file date modied and check
the date. I know how to look at each file name and I know how to remove
the file. I just can't figure out how to get access to the date last
modifed filed. Below is how I intend to access the file names in the
directory.
>>>import os,time,sys cachedirecto ry="c:\\informa tica\\cache\\" v_filename_a rray=os.listdir (cachedirectory )
since listdir only returns the last part of the full file path, it's
often easier to use glob.
for file in glob.glob("c:/informatics/cache/*"):
...
otherwise, you need to do os.path.join(ca chedirectory, file) for each
file in the filename list, to get a full path.
to get the age of a file, use os.path.getmtim e(filename). this returns
the modification time as seconds since a reference time (usually called
the "epoch". if you subtract this time from the current time, you get
the age (in seconds):
import glob, os, time
now = time.time()
for file in glob.glob("c:/informatics/cache/*"):
age = os.path.gettime (file) - now
print file, "is", age / 3600, "hours old"
adding code to remove old files should be straightforward .
</F> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Shawn McKenzie |
last post by:
Can someone help me with a query to get the date/time that a database was
last modified?
I looked at the SHOW command but there was no mention of this.
TIA,
Shawn
|
by: Random Person |
last post by:
Does anyone know how to use VBA to relink tables between two MS Access
databases? We have two databases, one with VBA code and the other with
data tables. The tables are referenced by linked tables in the database
where the code resides. If we move the database with the data tables to
a new directory, the links are no longer valid.
I tried to update the links by changing the Connect property and refreshing:
Set td = db.TableDefs(0)...
|
by: BW |
last post by:
I am creating an upload/download function for an extranet site. Files will
be uploaded to directory based upon the users login and associated project.
The function works as long as I use "c:\Temp" as the directory. When I use
any other hard coded directory or even Server.MapPath() the upload function
fails and returns the error: "Exception has been thrown by the target of an
invocation." Once I change the root directory to "c:\Temp",...
|
by: Shailesh Humbad |
last post by:
I figured out what was causing the "Access is Denied" error when
calling functions from referenced DLLs in my service. I've tried to
be very detailed, so bear with me.
It turns out that libraries I made myself were not having this
problem, but it only happened with a zip library I downloaded and
copied into my program's directory. When using classes from this
library, my service threw an "Access Is Denied" FileLoadException,
which...
|
by: troutbum |
last post by:
I am experiencing problems when one user has a document open through a
share pointing to the web site. I use the dsolefile to read the
contents of a particular directory and then display them in a
datalist. When the next user selects trys to run the page, the page
fails and I get a generic error message from the stack trace. I am
assuming that the document properties cannot be read when a file is
open, but it worked well in asp.
...
| |
by: LisaB |
last post by:
I am new to Visual Basic .Net and would like to build a simple application
that searches a directory and returns the Path, Size and DateModified of all
files that end in ".MDB".
a) I would create a form to allow the user to enter the directory to be
searched - EX.. "C:\" or "D:\Program FIles" would be entered by the user
------This is the part I need Help with----------
b) The form would have a button with the following on_Click...
|
by: Fish Womper |
last post by:
I am at best a part time developer of Access databases. I use Access
2.0, as this is all my employer has on its computers. Even so, to use
this ancient version requires a fairly convoluted installation
procedure on each PC on which it is used. I am self-taught from the
help files that come with Access 2.0 and from painful experience. I've
never attended any type of training course on how to develop databases
in Access.
I have no idea...
|
by: techusky |
last post by:
I made a script that successfully creates a .zip file of all the files
in a directory on my web server, but now what I haven't figured out
how to do is how to have it automatically deleted when the user
successfully downloads it, as otherwise my server would eventually get
clogged up with all these zip files.
Any help/suggestions?
Thanks
|
by: Bouzy |
last post by:
I am trying to make a script to check files in a folder, then see later if the files have been changed at all..
I have this working to make the original file (data log with files,file_sizes, and dates).
log_file = open('log_file.txt', 'w')
for root,dirs,files in os.walk(cwd):
for folder in glob.glob(root):
for file in glob.glob(folder + '/*.**'):
file_path = os.path.split(file)
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |