473,748 Members | 2,502 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 3638
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
3654
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
3420
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
7838
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
3661
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
10185
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
2908
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
2902
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
8780
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
2352
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
8831
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
9555
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...
1
9329
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
9250
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 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...
0
8247
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...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4878
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
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...

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.