I have the following code that is supposed to return the last modified date of a file as a string:
:getLastModifiedDate
@echo on
SETLOCAL enabledelayedexpansion
set FILE=%~f1
set FILE=!FILE:%NETWORK_DRIVE_SHARE_PATH%=%NETWORK_DRIVE_NAME%!
set FILE=%FILE:\=\\%
set RETURN_VALUE="internal script error"
for /f "tokens=* usebackq" %%d in (`wmic datafile where Name^="%FILE%" get lastmodified ^| findstr ^"[0-9]^"`) do ( set tmpd="%%d ddd"
echo 111111 %tmpd%
echo 222222 !tmpd!
echo 333333 %%tmpd%%
set RETURN_VALUE=%tmpd:~0,14%
)
(ENDLOCAL
set getLastModifiedDateResult=%RETURN_VALUE%
)
exit
@echo off
goto :eof
I expect that
set tmpd="%%d ddd"
sets at least ddd
as value for %tmpd%
.
However, during execution, nothing is done:
C:\Windows\system32>for /F "tokens=* usebackq" %d in (`wmic datafile where Name="S:\\Actually\\Existing File.csv" get lastmodified | findstr "[0-9]"`) do (
set tmpd="%d ddd"
echo 111111
echo 222222 !tmpd!
echo 333333 %tmpd%
set RETURN_VALUE=~0,14
)
I expect my for loop to be the cause for this problem. When I execute the exact same string in cmd.exe, I get a result:
C:\Users\uuuu>for /f "tokens=* usebackq" %d in (`wmic datafile where Name^="S:\\Actually\\Existing File.csv" get lastmodified ^| findstr ^"[0-9]^"`) do ( set tmpd=%d )
[xxx@yyy auf zzzz]
) sers\yc067xd>(set tmpd=20150413172700.000000+120
[yc067xd@R0199 auf FS00QHE0]
C:\Users\uuuu>echo %tmpd%
20150413172700.000000+120
Where did I do something wrong?