Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
shawn
- Posts: 2
- Joined: 13 May 2017 15:52
#1
Post
by shawn » 13 May 2017 16:11
Hi,
I want to get the last modified date and time of my *.txt files with the first script below.
I can get the last modified date but not the last modified time.
Code: Select all
for %%f in (C:\test\*.txt) do call :process %%f %%~tf
goto :eof
:process
set filepath=%1
set filedate=%2
echo %filedate%
rem It will return only the date 2017/05/13
With the following code, the date and time appear but i need to assign the value %%~tf in a variable in order to be able to format the date and the time
Code: Select all
for %%f in (C:\test\*.txt) do echo %%~tf
Could you help me to fix the first script please ?
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 13 May 2017 18:36
Because %%~tf contains a space and arguments passed to your subroutine are space-separated you would find the time in parameter %3.
In order to avoid this you need to enclose the arguments into quotation marks. These can be removed later on with the tilde (~) modifier of your parameters.
Code: Select all
for %%f in (C:\test\*.txt) do call :process "%%~f" "%%~tf"
goto :eof
:process
set "filepath=%~1"
set "filedate=%~2"
echo %filedate%
Steffen
-
shawn
- Posts: 2
- Joined: 13 May 2017 15:52
#3
Post
by shawn » 14 May 2017 09:57
Thank you very much aGerman for your help.