Computing.Net > Forums > Programming > folder to each file according to its creatio

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

folder to each file according to its creatio

Reply to Message Icon

Name: AnnaZEL
Date: June 22, 2009 at 07:12:35 Pacific
OS: Windows XP
Subcategory: Batch
Comment:

Hello

I want to make a new folder to each file according to its creation date

This is what I got so far
cd C:\Test\
for /f "skip=5 tokens=1-5" %%i in ('dir /tc /a-d') do (
echo %%i >> output_file
echo %%m >> output_file
set dt = %%i
echo %dt% >>output_file
)

but instead of dt value I get ECHO IS ON
(I have tried to set echo off but still, I didn't got dt value)

How can I get dt value?

Thank you very much



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: June 22, 2009 at 07:32:30 Pacific
Reply:

H:\>set /?
Displays, sets, or removes cmd.exe environment variables.

SET [variable=[string]]

 . . . . . . . . . . . . . . . . . . . . . . .

Finally, support for delayed environment variable expansion has been
added.  This support is always disabled by default, but may be
enabled/disabled via the /V command line switch to CMD.exe.  See CMD /?

Delayed environment variable expansion is useful for getting around
the limitations of the current expansion which happens when a line
of text is read, not when it is executed.  The following example
demonstrates the problem with immediate variable expansion:

    set VAR=before
    if "%VAR%" == "before" (
        set VAR=after
        if "%VAR%" == "after" @echo If you see this, it worked
    )

would never display the message, since the %VAR% in BOTH IF statements
is substituted when the first IF statement is read, since it logically
includes the body of the IF, which is a compound statement.  So the
IF inside the compound statement is really comparing "before" with
"after" which will never be equal.  Similarly, the following example
will not work as expected:

    set LIST=
    for %i in (*) do set LIST=%LIST% %i
    echo %LIST%

in that it will NOT build up a list of files in the current directory,
but instead will just set the LIST variable to the last file found.
Again, this is because the %LIST% is expanded just once when the
FOR statement is read, and at that time the LIST variable is empty.
So the actual FOR loop we are executing is:

    for %i in (*) do set LIST= %i

which just keeps setting LIST to the last file found.

Delayed environment variable expansion allows you to use a different
character (the exclamation mark) to expand environment variables at
execution time.  If delayed variable expansion is enabled, the above
examples could be written as follows to work as intended:

    set VAR=before
    if "%VAR%" == "before" (
        set VAR=after
        if "!VAR!" == "after" @echo If you see this, it worked
    )

    set LIST=
    for %i in (*) do set LIST=!LIST! %i
    echo %LIST%

See also: SETLOCAL /?


0
Reply to Message Icon

Related Posts

See More


Windows Programing Random command



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: folder to each file according to its creatio

Monitor folder for .txt file, www.computing.net/answers/programming/monitor-folder-for-txt-file-/15250.html

Output Newest Folder to Text File www.computing.net/answers/programming/output-newest-folder-to-text-file/17563.html

Copying files from one driver hive to another www.computing.net/answers/programming/copying-files-from-one-driver-hive-to-another/18970.html