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
date of a file
Moderator: DosItHelp
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
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
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
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
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
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
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
-
- Expert
- Posts: 80
- Joined: 04 Feb 2009 10:03
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!
)
)