|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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"; } |
|
#3
|
|||
|
|||
|
>> 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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > creating new files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|