Wednesday, February 2, 2011

DOS BATCH - (Read File Properties)

http://www.robvanderwoude.com/battech_fileproperties.php


Many times we need to check a file's size, its last-modified date, its location, or we may require its fully qualified path in short (8.3) notation.

Arguably CMD's most versatile internal command to the rescue: FOR.

FOR %%? IN (file_to_be_queried) DO (
ECHO File Name Only : %%~n?
ECHO File Extension : %%~x?
ECHO Name in 8.3 notation : %%~sn?
ECHO File Attributes : %%~a?
ECHO Located on Drive : %%~d?
ECHO File Size : %%~z?
ECHO Last-Modified Date : %%~t?
ECHO Parent Folder : %%~dp?
ECHO Fully Qualified Path : %%~f?
ECHO FQP in 8.3 notation : %%~sf?
ECHO Location in the PATH : %%~dp$PATH:?
)
pause


Note: Not all of these properties can be read this way in every Windows version. With every new Windows version, more options became available.
Type FOR /? for more details.

Many of these properties can be combined, as is shown for the s option (short, or 8.3 notation).

Play with it, experiment, and learn. Have fun.

No comments:

Post a Comment