Computing.Net > Forums > Programming > Quick Rename of a File to Yesterday

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Quick Rename of a File to Yesterday

Reply to Message Icon

Name: eposada
Date: July 6, 2005 at 12:32:18 Pacific
OS: Windows 2003
CPU/Ram: Pentium 4
Comment:

I am trying to automate a process that would create an existing file and renames it with yesterday's date..
existing file is coming as CSHTRN01.txt
my expectation is CI070605.MST
Where (07) is the current month, (06) current Day and (05) current year..
Please help



Sponsored Link
Ads by Google

Response Number 1
Name: dtech10
Date: July 6, 2005 at 14:52:20 Pacific
Reply:

Hi
I can set yesterday date into an environment variable, but how will the filename be given to the batch file, from the command line.
And the date variable always starts the the first letter of the filename.

The batch file will be quite involved as getting yesterdays date right for month endings and year endings, can be quite tricky.




0

Response Number 2
Name: Mechanix2Go
Date: July 6, 2005 at 23:38:00 Pacific
Reply:

Hi dtech10,

The 'yesterday' thing came up a few months ago.

I decided that a BAT was just too much of a kludge.

I worrked on a QB45 prog. It was pretty messy, since I'm not adept at the 'case'.

I guess I should dust it off and finish what I started.

M2


If at first you don't succeed, you're about average.


0

Response Number 3
Name: dtech10
Date: July 7, 2005 at 06:32:02 Pacific
Reply:

Hi M2
I managed to get a batch file that works
in WinXP, seems ok.
Just waiting for Eddie's reply.

QB is a better platform for this sort of program.


0

Response Number 4
Name: FishMonger
Date: July 7, 2005 at 08:48:44 Pacific
Reply:

Perl can calculate and format yesterdays date in 1 line of code (actually, 2 lines if you include the loading of the module). Additionaly, it would be platform independant so it would work on Windows, Linux, UNIX, and Mac.

use POSIX qw(strftime);
$date = strftime("%m%d%y", localtime(time - 86400));



0

Response Number 5
Name: Mechanix2Go
Date: July 7, 2005 at 10:47:21 Pacific
Reply:

FM,

How do you get it into a variable to use for renaming?

M2


If at first you don't succeed, you're about average.


0

Related Posts

See More



Response Number 6
Name: FishMonger
Date: July 7, 2005 at 12:03:52 Pacific
Reply:

In my example yesterday's date was put into a variable called $date.

Here's another example with explaination.

#!perl -w

# load the strict pragma
use strict;

# load the strftime function from the POSIX module.
use POSIX qw(strftime);

# pass the date format and current time minus 86400 seconds (1 day) and assign $date the result
my $date = strftime("%m%d%y", localtime(time - 86400));

# assign the $fname var the name of the new file
my $fname = "CI$date.MST";

# print the $fname var, verifing the desired name
print $fname;

#############

C:\>type test.pl
#!perl -w

use strict;
use POSIX qw(strftime);

my $date = strftime("%m%d%y", localtime(time - 86400));
my $fname = "CI$date.MST";

print $fname;

C:\>test.pl
CI070605.MST


0

Response Number 7
Name: FishMonger
Date: July 7, 2005 at 12:09:01 Pacific
Reply:

I left out the renaming part. Assuming the original file name is in a ver called $orig the renaming would look like:

rename($orig, $fname);


0
Reply to Message Icon

New to Java.... Need help with batch logi...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Quick Rename of a File to Yesterday

copying part of a file to another www.computing.net/answers/programming/copying-part-of-a-file-to-another/18680.html

Copy a file to system32 folder of multiple co www.computing.net/answers/programming/copy-a-file-to-system32-folder-of-multiple-co/19810.html

Length of a file in C www.computing.net/answers/programming/length-of-a-file-in-c/831.html