问题
When I use dir command in win XP it returns all kind of info:
Volume in drive C is OSDisk
Volume Serial Number is AEF7-B35F
Directory of C:\Users\bd250124\Desktop\test
06/11/2015 12:14 PM <DIR> .
06/11/2015 12:14 PM <DIR> ..
06/11/2015 12:14 PM 10 test01.txt
06/11/2015 12:13 PM 0 test02.txt
2 File(s) 10 bytes
2 Dir(s) 261,280,952,320 bytes free
The problem is that I don't need all that info, I need only file name and last write time. Is there any way to format it, google is not returning any results, and to repeat I'm on win XP and 2000.
回答1:
Command line:
for /F "delims=" %G in ('dir /B /A:-D') do @echo %~tG %G
Batch (note %%G
instead of %G
):
for /F "delims=" %%G in ('dir /B /A:-D') do @echo %%~tG %%G
Resources (required reading):
- (command reference) An A-Z Index of the Windows CMD command line
- (additional particularities) Windows CMD Shell Command Line Syntax
- (
%~G
etc. special page) Command Line arguments (Parameters)
回答2:
for %a in ("c:\somewhere\*" "d:\here\*.txt" "\\server\share\path\*.doc") do @echo %~ta %~fa
Use a simple for
command, indicate all the sets of files you want to process and for each file found (referenced by %a
) echo its time stamp (%~ta
) and the full path to the file (%~fa
)
For usage inside batch files, the percent signs need to be escaped, replacing each %
with %%
来源:https://stackoverflow.com/questions/30778419/how-to-format-dir-command-in-cmd-for-xp-and-win-2000