set _ForString=%~1
set _ForString=!_ForString:\=\\!
For /f "tokens=1,2* delims==" %%a in ('wmic datafile where name="!_ForString!" get LastModified /format:list') do (
echo %%a %%b
set %~2=%%b
)
Rem %1 is set to C:\Users%username%\CMDS.bat
I'm actually getting the error C:\\Users\\theBATeam\\CMDS.bat - Invalid alias verb.
There are two problems in the above code snippet:
- in
name="!_ForString!": you need to escape the equals sign as name^="!_ForString!";
- parsing
wmic output in a FOR /F loop (explained below).
:ParseWmicDatafile subroutine in the following commented .bat script should do the job:
@ECHO OFF
SETLOCAL EnableExtensions
call :ParseWmicDatafile "%~f0" LastModified
REM show all variables prefixed with an underscore
set _
goto :eof
:ParseWmicDatafile
REM inputs (by value): %1 is a fully qualified file name
REM %2 is a valid "wmic datafile" property name
REM outputs (by reference): _%~2 is a variable name drawn from supplied %2:
REM property name prefixed with an underscore
REM _ForString
REM remove residuary variable _%~2 (if present)
if defined _%~2 set "_%~2="
set "_ForString=%~1"
set "_ForString=%_ForString:\=\\%"
for /f "tokens=1* delims==" %%A in (
'wmic datafile where name^="%_ForString%" get %~2 /format:list'
) do for /f "delims=" %%b in ("%%~B") do (
echo %%A %%b
set "_%~2=%%b"
)
goto :eof
Here the for loops are
%%A to retrieve the LastModified property name (%%A) and value (%%B);
%%b to remove the ending carriage return in the value returned; wmic behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).
See Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem
Output:
==> D:\bat\SU\1396664.bat
LastModified 20190201220347.477320+060
_ForString=D:\\bat\\SU\\1396664.bat
_LastModified=20190201220347.477320+060
==>
wmic datafile where name="C:\\folder\\folder\\File.txt" get LastModified /format:listor something like that. I think you do not want AM/PM format though and you want00-24format on theYYYYMMDDhhmmstring format. Maybe this can work for you and you can iterate loop the file with aFOR /Rloop for something for the file name and path. Just a quick idea for you just in case. – Vomit IT - Chunky Mess Style Jan 22 '19 at 03:49No Instance(s) Available.I was able to convert AM/PM into a number (AM is 1, PM is 2) and put it before the time so it still applies as a larger number. – Mark Deven Jan 22 '19 at 13:38cd /dto the dir and then specify the file name only I think. – Vomit IT - Chunky Mess Style Jan 22 '19 at 13:41I can't use PowerShell for security reasons, but JScript and VBScript would be fine.
– Mark Deven Jan 22 '19 at 14:18\with\\so it can handle it, then parse it into that command. – Mark Deven Jan 22 '19 at 16:09C:\\Users\\theBATeam\\CMDS.bat - Invalid alias verb.Any ideas as to what that means? My script is: https://pastebin.com/raw/qvLwygB3 – Mark Deven Jan 22 '19 at 16:59For /f "tokens=1,2* delims==" %%a in (out.temp) do set %~2=%%bdoes nothing. If I make itFor /f "tokens=1,2* delims==" %%a in (out.temp) do echo helloit never echos hello. – Mark Deven Jan 24 '19 at 17:07