WMIC path Win32_Directory WHERE name="W:\\foldername" get lastmodified
returns something like this
LastModified
20140612095434.758265-240
I would like to put this in a batch file to assign the bolded portion of that string to a variable so I can use it later in the batch file.
Any help is appreciated!
This is my batch file so far for reference
@echo off
@cls
net use W: \\file\home\ex-employees
cd W:
W:
REM Get user ID
set /p id="Enter ID of user to Archive: "
REM Get last modified code goes here assigned to "LM" variable
REM
REM WMIC path Win32_Directory WHERE name='W:\\rsink' get lastmodified
REM Join Variables
call set filename=%%%id%%LM%%%
call zipjs.bat zipItem -source %id% -destination .\%filename%.zip -keep yes -force no
rmdir /S /Q %id%
Echo All Done!
@pause
WMIC path Win32_Directory WHERE name="W:\\foldername" get lastmodified
returns something like this
LastModified
20140612095434.758265-240
You can use a for /f
loop to do this. Here is a small example.
GetLastModifiedDate.cmd:
@echo off
rem GetLastModifedDate.cmd
setlocal enabledelayedexpansion
rem skip header line
rem use findstr to remove blank lines
for /f "skip=1 tokens=*" %%d in ('WMIC path Win32_Directory WHERE name^="f:\\test" get lastmodified ^| findstr /r /v "^$"') do (
set LM=%%d
rem required part is alway 8 chars yyyymmdd so strip first 8 chars
set LM=!LM:~0,8!
)
echo %LM%
endlocal
Your batch file with the needed modifications:
@echo off
@cls
setlocal enabledelayedexpansion
net use W: \\file\home\ex-employees
cd W:
W:
REM Get user ID
set /p id="Enter ID of user to Archive: "
REM Get last modified code goes here assigned to "LM" variable
rem skip header line
rem use findstr to remive blank lines
for /f "skip=1 tokens=*" %%d in ('WMIC path Win32_Directory WHERE name^="W:\\rsink" get lastmodified ^| findstr /r /v "^$"') do (
set LM=%%d
rem required part is alway 8 chars yyyymmdd so strip first 8 chars
set LM=!LM:~0,8!
)
REM Join Variables
call set filename=%%%id%%LM%%%
call zipjs.bat zipItem -source %id% -destination .\%filename%.zip -keep yes -force no
rmdir /S /Q %id%
Echo All Done!
@pause
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments