Solved

How to find out which remote directories I should be in?

Posted on 2008-10-07
8
149 Views
Last Modified: 2010-04-21
I'm connecting to a server thru FTP. Before I do a "cd" to a directory, I need to figure it out which directory. Every mid month the directory change, I need to know the best way of doing it.
below is like a table. The date has to be in between the from and to date, then directory will be set.

  From                           To                          directories
prev_yyyy-12-16 -> curr_yyyy-01-15 = curr_yyyy_01_report (directory)
curr_yyyy-01-16 -> curr_yyyy-02-15 = curr_yyyy_02_report (directory)
curr_yyyy-02-16 -> curr_yyyy-03-15 = curr_yyyy_03_report (directory)
curr_yyyy-03-16 -> curr_yyyy-04-15 = curr_yyyy_04_report (directory)
curr_yyyy-04-16 -> curr_yyyy-05-15 = curr_yyyy_05_report (directory)
curr_yyyy-05-16 -> curr_yyyy-06-15 = curr_yyyy_06_report (directory)
curr_yyyy-06-16 -> curr_yyyy-07-15 = curr_yyyy_07_report (directory)
curr_yyyy-07-16 -> curr_yyyy-08-15 = curr_yyyy_08_report (directory)
curr_yyyy-08-16 -> curr_yyyy-09-15 = curr_yyyy_09_report (directory)
curr_yyyy-09-16 -> curr_yyyy-10-15 = curr_yyyy_10_report (directory)
curr_yyyy-10-16 -> curr_yyyy-11-15 = curr_yyyy_11_report (directory)
curr_yyyy-11-16 -> curr_yyyy-12-15 = curr_yyyy_12_report (directory)
0
Comment
Question by:matgold
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:Adam314
ID: 22663498
I'm assuming prev_yyyy and curr_yyyy should be replaced by the previous or current 4-digit year.  Let me know if that isn't the case.

my @now = localtime();

$now[4]++;

$now[5]+=1900;
 

if($now[3] >= 16) {

	$now[4]++;

	if($now[4]>12) {

		$now[5]++;

		$now[4]=0;

	}

}

my $directory = sprintf("%4d_%02d_report", $now[5], $now[4]);

print "directory=$directory\n";

Open in new window

0
 

Author Comment

by:matgold
ID: 22664097
if date is between 2008-12-16 -> 2009-01-15
then dir should = 2009_01_report

the way it is now, it end up with 2009_00_report
0
 

Author Comment

by:matgold
ID: 22664192
ok, I changed $now[4]=0;
to $now[4]=01;
0
 

Author Comment

by:matgold
ID: 22664286
on the directory name, instead of 2009_00_report
I need to change it to 2009_00.report, with the dot.
when I do that, it mess up the
my $directory = sprintf("%4d_%02d.report", $now[5], $now[4]);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 39

Expert Comment

by:Adam314
ID: 22666177

#To simulate other dates:

#  Add to your script:  use Time::Local;

#  pass timelocal(sec,min,hour,day,month-1,year-1900) to localtime

#eg: my @now = localtime(timelocal(0, 0, 0, 18, 11, 108)); #18-dec-2008

my @now = localtime();

$now[4]++;

$now[5]+=1900;

 

if($now[3] >= 16) {

        $now[4]++;

        if($now[4]>12) {

                $now[5]++;

                $now[4]=1;

        }

}

my $directory = sprintf("%4d_%02d.report", $now[5], $now[4]);

print "directory=$directory\n";

Open in new window

0
 

Author Comment

by:matgold
ID: 22669871
I have a case where the directory is  
%4d_AP_%02d_abc:[DATA.%4d_AP_%02d.DAILY_REPORTS]

inside the bracket, the %4d becomes "   0" and %02d becomes "00"
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 50 total points
ID: 22670827
In the sprintf, you need to provide the substitution values in the order they are listed.

With your new directory, you'll need to provide the year and month twice each.
$directory = sprintf("%4d_AP_%02d_abc:[DATA.%4d_AP_%02d.DAILY_REPORTS]", $now[5], $now[4], $now[5], $now[4]);

Open in new window

0
 

Author Closing Comment

by:matgold
ID: 31503932
excellent!   Thank You Sir
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl search and replace 6 165
cpan issue 1 61
perl script to search for files containing text 3 73
Perl File::Find alternative 1 51
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

23 Experts available now in Live!

Get 1:1 Help Now