473,471 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

glob files by number sequence (date)

dlite922
1,584 Recognized Expert Top Contributor
Hey Guys,

I'm a PHP guy, but choose to do my file scripts in perl and have come upon this problem:

I have n files with a date in their name: test2010-08-23.txt for example.

I want grab (using glob or whatever else) the last x number of files.

Example assuming today is Aug 23rd, the last 4 days would grab the files for the 22nd, 21st, 20th, and 19th of August.
test2010-08-19.txt
test2010-08-20.txt
test2010-08-21.txt
test2010-08-22.txt

Is there a better way to do this other than back tracing with a -1 forloop?

Expand|Select|Wrap|Line Numbers
  1. // my current plan in *pseudo* code, the forloop
  2.  
  3. days = 7
  4. @testfiles = array(); 
  5.  
  6. for(i = days; i > 0; i--)
  7. {
  8.    aFile = 'test'.formatdate("yyyymmdd",today - i).'.txt'; 
  9.    if(file_exists(aFile)
  10.       push(@testfiles,aFile);
  11. }
  12.  
  13.  
  14.  
Just extending my perl knowledge.


Thanks All,


Dan
Aug 23 '10 #1
2 2318
Oralloy
988 Recognized Expert Contributor
Probably not for the date selection.

You will have to deal with month and year boundaries, so I'd suggest that you use a date processing module, and not just ad-hoc code. In the long run you'll save yourself a whole lot of grief.

Also, does your specification say the last four files, regardless of date, or just the files from the last four days? Something to think about.
Aug 23 '10 #2
dlite922
1,584 Recognized Expert Top Contributor
Yes, I am thinking about those things, but wanted to keep the post simple.

I'm going to use Date:Calc for the date processing.

I will be ignoring files that the dates do not exist. (i.e. if 3 files exist for the 4 files, then i'll only take 3 files)

It is for an averaging functions so in the end i'll sum the numbers I need from each file and divide by the number of files (in the above case: divide by 3 instead of 4).

Thanks Though!

I'll figure something out tomorrow and if solution is related to OP i'll post the code here.


Cheers,


Dan
Aug 24 '10 #3

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

Similar topics

5
by: Ken1 | last post by:
I am going to drop a primary key from one column and create a new column to be used as primary key in an existing database. The old column was a date column which someone earlier though was a good...
3
by: pluton | last post by:
Hallo, Hot to get unique, sequential number during execution of stored procedure ? I can create table with autoincrement column, add record, get ident_current and delete record each time i...
4
by: Mark | last post by:
Hi I have been trying to convert the week number to a range of dates that I can use. It should be fairly simple for you guru's out there but for us mere mortals it is beyond our grasp. I know...
2
by: Raed Sawalha | last post by:
I wondering if it possilble to get the directory files ordered by creation date string files = System.IO.Directory.GetFiles(strPath,"*.msg") can I sort the returned file by creation date? ...
0
by: Mike Carter | last post by:
I'd like to sort a directory of files by the "Date Picture Taken" column that appears for digital camera images in Explorer. How do I access this file property in code and is there a way to have...
3
by: Mal | last post by:
Hello, Any advice on a function to convert a given week number to a date? Ideally I'd like the first day of that week. I'm using this to compare year to year....using the week number as the...
1
by: Pankaj | last post by:
Hi I have two problems a) I have two form fields. In one of them, a user enters the date (in dd-mm-yyyy format, using a calendar) and in the second, he enters a number. I have to add this...
6
by: vdicarlo | last post by:
I am a programming amateur and a Python newbie who needs to convert about 100,000,000 strings of the form "1999-12-30" into ordinal dates for sorting, comparison, and calculations. Though my script...
2
by: moonbug | last post by:
How can I move files based on date specifically for the case below: 1. crontab runs every hour 2. any file in directory 1 dated less than the current hour is moved to directory 2. eg file1...
8
by: Wayne L | last post by:
I have searched and could not find my solution to my problem. I have a table that has a field that I want to start at 0001 and go to 1999. Once it reaches 1999 I want the field to reset to 0001. I...
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
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
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,...
1
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...
0
agi2029
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.