I have been using the following command to get the file date. However, the fileDate
variable has been returning blank value ever since we moved to a different server (Windows Server 2003).
FOR /f %%a in ('dir myfile.txt^|find /i " myfile.txt"') DO SET fileDate=%%a
Is there any other more reliable way to get the file date?
you can get a files modified date using vbscript too
save the above as mygetdate.vbs and on command line
Change
%
to%%
for use in batch file, for%~ta
syntax entercall /?
Useful reference to get file properties using a batch file, included is the last modified time:
It works for me on Vista. Some things to try:
Replace
find
with the fully-qualified path of the find command.find
is a common tool name. There's a unix find that is very differet from the Windows built-in find. like this:FOR /f %%a in ('dir ^|%windir%\system32\find.exe /i "myfile.txt"') DO SET fileDate=%%a
examine the output of the command in a cmd.exe window. To do that, You need to replace the %% with %.
FOR /f %a in ('dir ^|c:\windows\system32\find.exe /i "myfile.txt"') DO SET fileDate=%a
That may give you some ideas.
If that shows up as blank, then again, at a command prompt, try this:
dir | c:\windows\system32\find.exe /i "myfile.txt"
This should show you what you need to see.
If you still can't figure it out from that, edit your post to include what you see from these commands and someone will help you.
What output (exactly) does
dir myfile.txt
give in the current directory? What happens if you set the delimiters?(note the space after
delims=
)(to make life easier, you can do this from the command line by replacing
%%a
with%a
)You can do it