date of a file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
neuflex
Posts: 4
Joined: 09 Mar 2009 05:19

date of a file

#1 Post by neuflex » 09 Mar 2009 05:27

Hello,

iam having trouble finding the date of a file.

can i pass the date of when a file was created to a variable?

I then to move it if its a centain date

thanks in advance

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#2 Post by RElliott63 » 09 Mar 2009 07:52

What date?

Is this the date the file was created? Or, is the date inside the name of the file? (ie FileName-20090309.txt)

Need some additional information here.

What are you trying to do with the file?

-R

neuflex
Posts: 4
Joined: 09 Mar 2009 05:19

#3 Post by neuflex » 09 Mar 2009 08:42

it is the date for file was created

I have worked out how to display the date for example: -

FOR %%i IN (test.txt) DO (

ECHO Last-Modified Date : %%~ti SET %var = %ti%

)

when i try and pass %ti% to %var and display that it dont like it

and when i try and echo %var I want it to display the date it was created

then if its a centain date move it to a different directory

Thanks

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#4 Post by RElliott63 » 09 Mar 2009 11:20

Try something similar to:

Code: Select all

SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION

Echo Enter Date for file selection
Set /P indate=Date:

If /I [%indate%] equ [] goto Exit

Echo Selecting files with a modified date of %indate%
Echo;

FOR %%i IN (test.txt) DO (
     Set "n=%%~nxi"
     Set "ti=%%~ti"

     If /I [!ti!] equ [%indate%] (
        Echo --Moving File Name: !n!  Last Modified:  !ti!
        Move %%i \NewFolder
     )  Else (
        Echo --Skipping File:  !n!
     )
)

:Exit


neuflex
Posts: 4
Joined: 09 Mar 2009 05:19

#5 Post by neuflex » 09 Mar 2009 13:33

thanks for your help :)

I am still having a few problems tho

I think for some reason when it returns the Date back via "ti" it also returns the time as well ie:-

Code: Select all

!ti! = 09/03/2009 18:08 

I have tryed to modifie the string:-

Code: Select all

set ti=%ti:~0,10%

if i just and echo the string !ti! again i get rubbish

or maybe there an easy way round it?

Thanks again :)

RElliott63
Expert
Posts: 80
Joined: 04 Feb 2009 10:03

#6 Post by RElliott63 » 09 Mar 2009 14:28

Try this instead...


Code: Select all

FOR %%i IN (test.txt) DO ( 
     Set "n=%%~nxi"
     Set "ti=%%~ti"
     Set "da=!ti:~0,10!"

     If /I [!ti!] equ [%indate%] (
        Echo --Moving File Name: !n!  Last Modified:  !da!
        Move %%i \NewFolder
     )  Else (
        Echo --Skipping File:  !n!
     )
)

neuflex
Posts: 4
Joined: 09 Mar 2009 05:19

#7 Post by neuflex » 09 Mar 2009 15:00

its works :) thanks so much for your help

Post Reply