Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 20th, 2001, 03:49 AM
Flink Flink is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2000
Location: Manchester, UK
Posts: 47 Flink User rank is Private First Class (20 - 50 Reputation Level)Flink User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 h 48 m 9 sec
Reputation Power: 8
creating new files

I've got a directory with say 30 files named after the date in the format of yy/mm/dd (e.g. 20010620 which would be the 20th of June).
What I need to do is read a number sent from an html form (no problem), process this as being the number of new files to create, and create a new file with the filename incremented and charmodded to 0777.
So if the user sent '15', 15 new files would be created, set to 777, and each filename would represent the date following the previous filename.
Any ideas?
So far, I've read each file in the directory into an array, and got the name of the last element in this array (the last file), and then tried to process it a bit. Can anyone help? Any ideas? Please...?
Thanks
Flink

Reply With Quote
  #2  
Old June 20th, 2001, 10:03 AM
mullaney mullaney is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 0 mullaney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Flink,

Try this. Remember, however, to add a check routine to ensure that you're not overwriting file which already exisit.

Bob

# Outputs files as yyyymmdd.n

$count = 15; #whatever you get from the form.

# Get current date and format it.
@date = localtime();
$year = ($date[5] + 1900);
$mon = ($date[4] + 1);
if ($mon < 10) {
$mon = "0$mon";
}
$day = $date[3];
if ($day < 10) {
$day = "0$day";
}

$newfile = "$year$mon$day";
for ($i=0;$i <= $count; $i++) {
open (FILE, "> $newfile.$i");
close (FILE);
chmod 0777, "$newfile.$i";
}

Reply With Quote
  #3  
Old June 22nd, 2001, 07:35 AM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> open (FILE, "> $newfile.$i");

You probably should use full path like so:

$path = "/path/to/my/dat/dir";
open (FILE, "> $path/$newfile.$i");

and chmod /path/to/my/dat/[/b]dir[/b] 777.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > creating new files


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway