473,699 Members | 2,287 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Copying files from a dir that were created in a specific date range

8 New Member
Hi,

How can i make a script to copy a bunch of files in a specific directory, that were created in a specifc date range?

Thanks in advance,
Teixeira
Aug 18 '07 #1
9 3635
numberwhun
3,509 Recognized Expert Moderator Specialist
First, we are definitely going to want to see your code that you have been working with so we can help you troubleshoot it. (don't forget the code tags around it).

When copying a directory, I would start by reading File::Copy::Rec ursive. As for the date of the file, there are a number of ways to do this, but we will want to know more first. Like, are you doing the copy based on a specific (fixed) date range or a date range that is a specific age (ie: 5 days back after 30 days have passed).

Also, what operating system are you working on?

Regards,

Jeff
Aug 18 '07 #2
teixeira
8 New Member
Hi,

i'm working in FreeBSD.
I wanna copy the files in a directory "/usr/local/var/qmailscan/quarantine" from 15 July 2007 until 18 July 2007.

I actually didn't start almost anyhing, i was just making some experiences with File::Copy() which was the function i googled and supposlly would help-me.

Thanks,
Teixeira
Aug 18 '07 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
Yes, File::Copy will help you with copying the files as you need, but since you are looking for specific dates, then I would suggest a Regular Expression to pull out the date field(s) and do a comparison to see if they match what you need.

Regards,

Jeff
Aug 18 '07 #4
teixeira
8 New Member
Thanks,

i'll learn more about regular expressions because i'm not inside regular expressions world yet.
If you could make a simple code sample for me to have as a guideline i'd appreciate very much.

Thanks and have a nice weekend.
Teixeira
Aug 18 '07 #5
KevinADC
4,059 Recognized Expert Specialist
I would consider using the grep() function and stat() to first collect a list of the files you are interested in copying. Then use File::Copy to copy them.

Expand|Select|Wrap|Line Numbers
  1. use File::Copy;
  2. chdir('path/to/folder') or die "$!";
  3. opendir(DIR,'.') or die "$!";
  4. my @list = grep {here you calculate the date range using stat()}  readdir DIR;
  5. close DIR;
  6. foreach my $file (@list) {
  7.    copy file stuff here
  8. }   
You could do it in one loop through the directory but I find it's often beneificial to make a list/array first when doing work like this.

perldoc: stat function

You can look up the other functions on the same website I linked you to.
Aug 18 '07 #6
teixeira
8 New Member
thanks for your answer.

i searched a little more and i found an easier way to list files, attendding to my reduced experience in perl.
Here's the script

Expand|Select|Wrap|Line Numbers
  1. chdir("/home/myname/Desktop"); #changes dir
  2. @files = <*>;   #get an array with all filenames
  3.  
  4. foreach $file (@files)
  5. {
  6.   $t=stat($file)[9];  #here i tried to use the function you suggested me to get the  datetime of the creation of file
  7.  
  8.   if($t=="2007-07-17")
  9.   {
  10.     print $t . "\n";  
  11.   }
  12. }
  13.  
  14.  
it raises an error compiling....
Maybe it can be a very simple thing to understand but not for me.
I've 3years experience working with vb and c# and get inside perl don't seem to be easy stuff by the way i dont have a nice IDE with intellisense to program perl i must use nano editor which difficult a little bit more ;)

Best regards,
Teixeira
Aug 21 '07 #7
numberwhun
3,509 Recognized Expert Moderator Specialist
For an editor that has an intellisense type system, try Komodo from Active State. It is what I use to code and it has saved me a few times.

Regards,

Jeff
Aug 21 '07 #8
teixeira
8 New Member
Thanks Jeff it looks nice, i'll give a try in de free demo

Best regards,
Teixeira
Aug 21 '07 #9
numberwhun
3,509 Recognized Expert Moderator Specialist
Cool! Glad you like the looks of it. In my opinion, it is one of the better editors out there. Granted, its a bit pricey, but it handles multiple languages (perl, python, php, tcl/tk, html, etc). Its really quite versatile.

LOL! I sound like an add for the IDE. I should bill them for it.

Regards,

Jeff
Aug 21 '07 #10

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

Similar topics

3
3647
by: Robert Tarantino | last post by:
Hello, I am trying to find a way to create a scheduled task or service that will copy my local profile folders under "Documents and settings" to a network drive. This would allow me to restore my settings if my profile became tampered with or corrupt. Is there any sample code available out there? -Robert
2
3416
by: David Mitchell | last post by:
I have tried using the following code to count the specific number of each weekday but get a compile error "User defined type not defined" which I think relates to the first line of the function: - Public Function HowManySpecificDays(StartDate As Date, EndDate As Date) As DayCounts and specifically the word "DayCounts" Can anyone help?
10
7832
by: Martin Ho | last post by:
I am running into one really big problem. I wrote a script in vb.net to make a copy of folders and subfolder to another destination: - in 'from.txt' I specify which folders to copy - in 'to.txt' I specify where to copy it - After I read content of 'to.txt' I create one more subfolder named by current date and thats where everything gets to be copied
4
3659
by: Robert Iver | last post by:
Hello everyone, I am trying to create an application that utilizes a SQL Mobile database. I have included that database in my main project, and it compiles and debugs just fine. I then created a custom installer project packaged as a class library and made an installer project to wrap the whole thing up into an MSI package. Basically the idea behind doing all this is so the handheld app can be pushed out through group policy.
3
10161
by: tkpmep | last post by:
I'd like to create a list of all files in a directory that were created after a certain date. How does one do this? I've used glob.glob to create a list of all files whose name matches a substring, but I don't see how I can use it to identify files by their creation date. Thanks in advance for the assistance. Thomas Philips
3
2906
by: richie9648 | last post by:
Hi All I have created a macro which turns reports done by users into a format that is needed by me. The good this is that all the reports are in the same format. However my question is around automating this process especially when there could be potentially hundreds of files by users that need converting. Is there a way a routine could be run automatically which opened all the files on the drive that had been created by users, format...
4
2899
by: MAdcock | last post by:
Hi, I have created an excel program which creates 65 or more (nneds to be unlimited) customised letters for clients. The macro uses VLOOKUP to change the details within the letter and copies / moves the work sheet to another "template file" which contains printing macros etc. Each new worksheet is subsequently renamed to the Client ID reference. The program is meant to do all applicable clients letters and then saves the template...
5
8773
by: Albert-jan Roskam | last post by:
Hi, I wrote the program below to merge all xls files in a given directory into one multisheet xls file. It uses xlwt and xlrd. The xls files I use for input are generated by Spss. When I open and re-save the files in Excel, the program works, but when I use the xls files as they were created by Spss, the program returns an error message (see below). Some details: Python 2.4, xlwt version 0.7.0, xlrd version 0.5.2, Win NT. Any ideas? ...
0
2351
by: Albert-jan Roskam | last post by:
Hi John, Thanks! Using a higher xlrd version did the trick! Regarding your other remarks: -yep, input files with multiple sheets don't work yet. I kinda repressed that ;-) Spss outputs only single-sheet xls files, but I agree it's nicer if the programs works in other cases too. -and no, I don't intend to use data fields. Wouldn't it be easier to convert those to string values if I ever came across them? Thanks again! Albert-Jan
0
8622
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,...
0
9184
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, 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...
0
9045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8930
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7761
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, 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...
1
6538
isladogs
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...
0
5878
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();...
1
3061
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
2
2358
muto222
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.