Reputation: 537
I want to extract the file last update date and time for a specific file called settings.xml in a network directory and write it to a local log file. Below is what I tried.
PUSHD "%share%"
forfiles /s /m settings.xml /c "cmd /c SET fileDate=@fDate SET fileTime=@ftime"
forfiles /s /m settings.xml /c "cmd /c SET fileDate=@fDate SET fileTime=@ftime"
POPD
ECHO %fileDate% %fileTime% >> "LOGFILE.TXT"
Where %share% is the network location and LOGFILE.TXT is on my local machine where the batch script runs. However, this only logs Echo is Off. on the log file.
I tried the following, but that wrote the information on the network drive itself, which is not what I want.
PUSHD "%share%"
forfiles /s /m settings.xml /c "cmd /c ECHO @fDate @ftime >> LOGFILE.TXT"
POPD
So, how do I extract the date and time from network location, but write it to a local file? I need to store that information in a variable and later use that variable, but I just don't know how to do it. I am trying my hands on batch script for the first time.
UPDATE 1 Tried the following based on comments. Still not printing the time.
SET current=%CD%
PUSHD "%share%"
forfiles /s /m settings.xml /c "cmd /c ECHO @ftime >> "%current%\LOGFILE.TXT""
POPD
Upvotes: 0
Views: 454
Reputation: 14290
I am going to provide a solution using FOR /R instead as this is much faster. The only caveat is that the date time modifier does not show seconds on the time.
FOR /R "%share%" %%G IN (settings.xml) DO echo %%~tG >>logfile.txt
On a side note, just wanted to prove that using FORFILES
with the other examples works as well.
@echo off
set share=H:\
SET current=%CD%
PUSHD "%share%"
forfiles /s /m temp.txt /c "cmd /c ECHO @ftime >>"%current%\LOGFILE.TXT""
POPD
type logfile.txt
pause
output
C:\Users\Squashman\Desktop>so.bat
1:31:04 PM
9:23:58 AM
12:42:34 PM
Press any key to continue . . .
Upvotes: 3