MODIFIED DATE AN D TIME

Discussion in 'Perl Misc' started by teambcdsoftware@gmail.com, Nov 6, 2005.

  1. Guest

    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
     
    , Nov 6, 2005
    #1
    1. Advertising

  2. Matt Garrish Guest

    <> wrote in message
    news:...
    > 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
     
    Matt Garrish, Nov 6, 2005
    #2
    1. Advertising

  3. Guest

    Matt Garrish wrote:
    > <> wrote in message
    > > 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.

    > ... 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.
     
    , Nov 6, 2005
    #3
  4. Guest

    Hi Matt,

    I thought that
    >> 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.

    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);
    ====================================================

    Matt Garrish wrote:
    > <> wrote in message
    > news:...
    > > 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
     
    , Nov 7, 2005
    #4
  5. robic0 Guest

    On 7 Nov 2005 02:10:40 -0800, wrote:

    >Hi Matt,
    >
    >I thought that
    >>> 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.

    >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.

    >====================================================
    >
    >Matt Garrish wrote:
    >> <> wrote in message
    >> news:...
    >> > 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
     
    robic0, Nov 12, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,367
    Michael Borgwardt
    May 30, 2004
  2. Roedy Green

    Date last Accessed vs Date Modified

    Roedy Green, Feb 21, 2008, in forum: Java
    Replies:
    1
    Views:
    1,529
    Nigel Wade
    Feb 22, 2008
  3. Guest
    Replies:
    2
    Views:
    191
    J. Gleixner
    Oct 1, 2004
  4. MODIFIED DATE AN D TIME

    , Nov 6, 2005, in forum: Perl Misc
    Replies:
    0
    Views:
    110
  5. Cartoper
    Replies:
    2
    Views:
    401
    Henry
    Feb 18, 2008
Loading...

Share This Page