CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Create new folder with the current month as the folder name

 



allensim81
New User

Jul 23, 2009, 2:24 AM

Post #1 of 3 (447 views)
Create new folder with the current month as the folder name Can't Post

HI,

I am newbie in Perl. Can anyone guide me how to create a folder with the current month as the folder name? What variable should i declare?

Following is my code:


Code
  

#!/usr/bin/perl

$websites="/data/websites";

opendir(DIR, $websites);
@files=readdir(DIR);
closedir(DIR);

for $file(@files) {
## List all files and directories from /data/websites ##
next if ($file =~ /^\./); # Ignore anything start with dot "."
next if (!-d "$websites/$file"); # Ignore if it is not a directory
next if ($file =~ /hts-cache/); # Ignore if it is hts-cache dir
print "[$file]\n";

## read hts-log.txt file ##
open F, "$websites/$file/hts-log.txt";
read F, $buf, 9999;
close F;

## Grab the URL from the file content ##
#print "[$buf]\n";
$buf=~/\d at (.*?) /;
$url=$1;
print "url=[$url]\n";

print "EXECUTE: hkk -q -%i -w $url -O \"/data/websites/month/$file\" -n -%P -N0 -s2 -p7 -D -a -K0 -c4 -%k -r1 -%e1 -A25000)";
system("hkk -q -%i -w $url -O \"/data/websites/month/$file\" -n -%P -N0 -s2 -p7 -D -a -K0 -c4 -%k -r1 -%e1 -A25000");



What should i put on "month" -O \"/data/websites/month/$file\" so tht the folder name will show the current month?

Can you please guide me step by step? Thanks in advance.


FishMonger
Veteran / Moderator

Jul 23, 2009, 5:37 AM

Post #2 of 3 (440 views)
Re: [allensim81] Create new folder with the current month as the folder name [In reply to] Can't Post

use POSIX 'strftime';

my $month = strftime("%B", localtime); # gets full name July

or

my $month = strftime("%b", localtime); # gets abbreviated name Jul

http://linux.die.net/man/3/strftime


(This post was edited by FishMonger on Jul 23, 2009, 5:38 AM)


KevinR
Veteran


Jul 23, 2009, 10:01 AM

Post #3 of 3 (433 views)
Re: [allensim81] Create new folder with the current month as the folder name [In reply to] Can't Post

The problem is that this is not perl:


Code
system("hkk -q -%i -w $url -O \"/data/websites/month/$file\" -n -%P -N0 -s2 -p7 -D -a -K0 -c4 -%k -r1 -%e1 -A25000");



Its just a wrapper around some OS code. If you want to stick with that then ask on a forum that deals with the OS you are running that on or wait and maybe someone here will be able to answer you.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives