0

I am trying to making a bat file that creates a directory, in that folder there are multiple sub-folders. When the file is run there is a file called testfile.csv that is suppose to be created and go to each of the sub-folders that are created upon the file being executed. I cannot figure out how to have the file end up in all of the sub-folders.

@ECHO OFF

@echo SET variables

echo starting ..... %testfile%

SET LOG_DIR=C:\Audit\Q_One
SET LOG_NM=testfile%.csv

 md C:\Audit\Q_One\MISAG 
 md C:\Audit\Q_One\MITAW  
 md C:\Audit\Q_One\NYAMS  
 md C:\Audit\Q_One\NYBIN 
 md C:\Audit\Q_One\WIAPP 
 md C:\Audit\Q_One\WIMIL


PAUSE

echo log path and name ..... %LOG_DIR%\%LOG_NM%
echo
echo Database is .... %tkdb%

PAUSE

REM create a log file names [script]_DYYYYMMDD_THHMMSS.txt
SET log=%LOG_DIR%\%me%_D%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%_T%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.txt

Echo " Running schedule: " %testfile%  On %DATE% at %TIME% 1>> "%log%"
echo " here I am "
echo PSAE is: %PSAE%

echo $null > %LOG_DIR%\%LOG_NM%

ECHO "!!!!!!  FINISHED !!!!!"  On %DATE% at %TIME% 1>> "%log%"
ECHO "!!!!!!  FINISHED !!!!!"

PAUSE
3
  • for /d %%a in ("C:\Audit\Q_One\*") do echo %%a should be helpful Commented Dec 11, 2019 at 20:00
  • When I ran that it created all of the sub-folders but didn't put the file into the sub-folders Commented Dec 11, 2019 at 20:13
  • maybe because echo doesn't copy files? Commented Dec 11, 2019 at 20:27

1 Answer 1

1
@(SETLOCAL
  ECHO OFF
  echo SET variables
  echo starting ..... %testfile%
  SET "LOG_DIR=C:\Audit\Q_One"
  SET "LOG_NM=testfile.csv"
  REM create a log file names [script]_DYYYYMMDD_THHMMSS.txt
  SET "log=%~n0_D%DATE:~10,4%%DATE:~4,2%%DATE:~7,2%_T%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%.txt"
  SET "tkdb=something"
)

PAUSE
echo log path and name ..... "%LOG_DIR%\%LOG%"
echo=
echo=Database is .... %tkdb%
echo=

MD "%LOG_DIR%\"

CALL echo " Running schedule: " %testfile%  On %%DATE%% at %TIME% 1>> "%LOG_DIR%\%log%"

PAUSE

FOR %%_ IN (
  "MISAG"
  "MITAW"  
  "NYAMS" 
  "NYBIN" 
  "WIAPP"
  "WIMIL"
) DO (
  IF NOT EXIST "%LOG_DIR%\%%_\" ( MD "%LOG_DIR%\%%_\" )
  echo=" here I am "
  echo=Folder is: "%%_"
  echo=PSAE is: "%PSAE%"

  echo $null > "%LOG_DIR%\%%_\%LOG_NM%"
  echo LOG_NM path and name ..... "%LOG_DIR%\%%_\%LOG_NM%"
)

ECHO "!!!!!!  FINISHED !!!!!"  On %DATE% at %TIME% 1>> "%log%"
ECHO "!!!!!!  FINISHED !!!!!"

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

5 Comments

That made it so that the log file is in all of the sub-folders, but the .csv file still isnt showing up inside the sub-folders. Maybe I can tweak CALL echo " Running schedule: " %testfile% On %%DATE%% at %TIME% 1>> "%LOG_DIR%\%%_\%log%" to fix that?
@LDrizzy , Oh, I miss read the unformatted block of text you wrote, you wanted the CSV, I'll just amend the code slightly
@LDrizzy Okay ammended, now the "lol" is in the root folder, and the "NM_LOG" file is created in the sub directories
After doing some more testing when i go through the for loop it sends the output file to the first sub folder (MISAG) but doesn't loop through the other sub folders, any idea how to make the loop go through all of the sub-folders?
@LDrizzy I'm essentially guessing as to what you wanted, based off me interpreting your original question. If you can write exactly what you expact at source and each destination I can better assist.

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.