MODIFIED DATE AN D TIME

  • Thread starter teambcdsoftware
  • Start date
T

teambcdsoftware

Hello,

Activestate,Windows XP + Perl 5.8
I need some help with a function that I use to create files.
I have a source file that I use to get parameters to create the new
files.
I need to get the modified date and time of the source file and set the
last modified date of the new file to the source file's last modified
date.
code so far
==========================================
use Date::Manip;

$modified = time - ((-M $file) * 86400);
$filemdate = localtime($modified);
$filemdate = UnixDate ($filemdate, "%Y%m%d - %H%M%S");
print "$filemdate\n";

But this is a value that changes as time changes and is not static....
Please help if you can.
Thanks
 
M

Matt Garrish

Hello,

Activestate,Windows XP + Perl 5.8
I need some help with a function that I use to create files.
I have a source file that I use to get parameters to create the new
files.
I need to get the modified date and time of the source file and set the
last modified date of the new file to the source file's last modified
date.
code so far
==========================================
use Date::Manip;

$modified = time - ((-M $file) * 86400);
$filemdate = localtime($modified);
$filemdate = UnixDate ($filemdate, "%Y%m%d - %H%M%S");
print "$filemdate\n";

But this is a value that changes as time changes and is not static....
Please help if you can.

Please help with what? Why are you doing any of the above when you said your
goal is to set the files to have the same modified time? Please take a look
at the Win32API-File-Time module and see if it meets your needs, otherwise
try and make it clearer what you're hoping to accomplish.

Matt
 
U

usenet

Matt said:
... Please take a look
at the Win32API-File-Time module and see if it meets your needs, otherwise
try and make it clearer what you're hoping to accomplish.

Or maybe File::Touch. But I also could not figure out exactly what the
OP was asking.
 
T

teambcdsoftware

Hi Matt,

I thought thatwas pretty clear as to what I wanted to do.
Maybe it was unclear that what I posted was only the code snippet of
what I was using to get the Modified File Date/Time.
I had a look at the module you suggested and got some code to work.
Thanks

Code:

===================================================
use Win32API::File::Time qw{:win};


#Get the file times
($atime, $mtime, undef) = GetFileTime ($filename);
$mtimeB = localtime ($mtime);
#Format time as I need it
$mtimeB = UnixDate ($mtimeB, "%Y%m%d - %H%M%S");

#Set the file times
SetFileTime ($filename, $atime, $mtime, undef);
====================================================
 
R

robic0

Hi Matt,

I thought that
was pretty clear as to what I wanted to do.
Maybe it was unclear that what I posted was only the code snippet of
what I was using to get the Modified File Date/Time.
I had a look at the module you suggested and got some code to work.
Thanks

Code:

===================================================
use Win32API::File::Time qw{:win};


#Get the file times
($atime, $mtime, undef) = GetFileTime ($filename); ^^^^^ ^^^^^
$mtimeB = localtime ($mtime);
#Format time as I need it
$mtimeB = UnixDate ($mtimeB, "%Y%m%d - %H%M%S"); ^^^^^^^^

#Set the file times
SetFileTime ($filename, $atime, $mtime, undef);
^^^^^ ^^^^^
I haven't looked at that Time module, but unless
UnixDate changes $atime and $mtime, GetFileTime
and SetFileTime are working with the same time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top