Page 1 of 1
date of a file
Posted: 09 Mar 2009 05:27
by neuflex
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
Posted: 09 Mar 2009 07:52
by RElliott63
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
Posted: 09 Mar 2009 08:42
by neuflex
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
Posted: 09 Mar 2009 11:20
by RElliott63
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
Posted: 09 Mar 2009 13:33
by neuflex
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:-
I have tryed to modifie the string:-
if i just and echo the string !ti! again i get rubbish
or maybe there an easy way round it?
Thanks again
Posted: 09 Mar 2009 14:28
by RElliott63
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!
)
)
Posted: 09 Mar 2009 15:00
by neuflex
its works
thanks so much for your help