0
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:?
)

I saw this at http://www.robvanderwoude.com/battech_fileproperties.php.

But when I try to apply it, In the loop and i using "set"

SET datetime_t = %%~t?

Echo datetime_t %datetime_t% > result.txt

inside the file only shown

datetime_t
datetime_t
datetime_t
datetime_t

what happen to this variable?is it empty?

2
  • yes - %%-Variables are only valid in the current block between ( and ) and not existent outside of this block. Commented Nov 11, 2013 at 9:07
  • Don't use a wildcard in a for loop variable. It is poor practice for people trying to learn by reading your code. Commented Nov 11, 2013 at 14:53

1 Answer 1

1

Try this:

setlocal enabledelayedexpansion
Rem Above is required for this to work

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:?

SET datetime_t=%%~t?
Echo datetime_t !datetime_t! > result.txt
Rem Notice use of "!"
)

And that should work fine.

Mona

Sign up to request clarification or add additional context in comments.

2 Comments

Hi, I wish to ask that, in a for loop, I saw some coding with %%?,%%#.Is it same meaning as a temporary variable like %%a, %%b that used in a for loop? or it bringing out the special meaning with the use of ? and #. I don't how to identify this problem as google are not accepting special character.
@user2940018 The use of ? or '#' is just to show that you can substitute with any letter you want. It can be used for some other purposes, but you don't need to worry about that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.