perl creating a new folder named with todays date

Posted on 2007-07-30
Last Modified: 2008-01-09
I have a perl script that opens a webpage, gets all the .txt links from the page and savesw each link as a file in $SaveDir

Right now $SaveDir is static  

my $SaveDir = "I:/SECDocs/20070730/";

Every time it runs, I manually have to create a new folder with a matching name.

I would like script to create a new folder everyday on its own like:
my $SaveDir = "I:/SECDocs/$TodaysDate/";

How do I set $TodaysDate to be todays date and create a folder with that name?

Heres what I have:

use strict;
use warnings;
use LWP::Simple;
use Data::Dumper;
use HTML::SimpleLinkExtor;

#Update these as necessary

my @Pages = (


my $SaveDir = "I:/SECDocs/20070730/";

      #Make sure SaveDir ends in /
      $SaveDir .= "/" unless $SaveDir =~ /\/$/;

foreach  my $Page (@Pages) {

      #Get page and it's links
      GetPageAndLinks($SaveDir, $Page);

sub GetPageAndLinks {
      my ($dir, $page) = @_;
      my $content = get($page);
      # Check the outcome of the response
      unless(defined($content)) {
            print STDERR "Could not get '$page': $@.\n";
      my $extor = HTML::SimpleLinkExtor->new();
      my @all_links = $extor->links;
      @all_links = grep {m!/Archives/edgar/data/.*\.txt!} @all_links;
      @all_links = map { $_ = "$_"; } @all_links;
      foreach my $one_link (@all_links) {
            my $FileName = $one_link;
            $FileName =~ s/.*[\/]//;   #Remove leading info
            $FileName =~ s/\?.*//;     #Remove trailing info
            getstore($one_link, "$dir$FileName");
      print "$FileName";

Question by:mcgilljd
    1 Comment
    LVL 39

    Accepted Solution

    use POSIX qw(strftime);

    my $TodaysDate= strftime("%Y%m%d",localtime);
    mkdir($TodaysDate) or die "Could not create dir $TodaysDate: $!\n";

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now