Scott
Scott

Reputation: 2760

Batch - Get Today's Date and Use It in the Name of a Directory I Need to Search

I have the following, which compares the contents of two directories and keeps a list of where a folder in one does not exist in the other:

setLocal EnableDelayedExpansion

set "DMZFolder=%WD_DIR%"
set "AMSFolder=D:\Apps\AMS\Files\Orig\UOB\BACKUP"

set count=0
for /f "delims=" %%F in ('dir/b/a-d "%DMZFolder%"') do (
    if not exist "%AMSFolder%\%%F" (
         set /A count+=1
         REM keep file name and put in email later
         set list[!count!]=%%F 
    )
)

Now, rather than search the DMZFolder, I want to get today's date, format it, and add it to DMZFolder to create a new directory to search. So, if the original directory is

C:\DMZFolder\directory

the new directory might be

C:\DMZFolder\directory\2019-12-05

I do this to get today's date:

SET Today=%Date:~10,4%-%Date:~4,2%-%Date:~7,2%

So far, so good. How do I add the string that Today now contains to what is in my DMZFolder variable?

Upvotes: 0

Views: 125

Answers (2)

user7818749
user7818749

Reputation:

I would rather use wmic:

@echo off
for /f "usebackq tokens=1,2 delims=,=- " %%a in (`wmic os get LocalDateTime /value`) do @if %%i==LocalDateTime (
     set string=%%b
)
set Today=%token10:~0,4%-%token10:~4,2%-%token10:~6,2%
set "DMZFolder=%WD_DIR%\%Today%"

Locale differs on devices, so using wmic will be the same across all windows devices.

Upvotes: 1

Scott
Scott

Reputation: 2760

I figured it out: set "DMZFolder=%WD_DIR%\%Today%"

Upvotes: 0

Related Questions