0

I currently have a script I have been working on for a few hours and having some trouble. What it does is takes all .dat files in the C:\TEST\WF\ directory and renames it to the folder name plus .txt. However it is not renaming the files to the folder name, it grabs the previous folder instead

Example:

Source Directory:

  1. C:\TEST\WF\FOLDER1\FILE.dat
  2. C:\TEST\WF\FOLDER2\FILE.dat
  3. C:\TEST\WF\FOLDER3\FILE.dat

Current output:

  1. C:\TEST\WF\FOLDER1\WF.txt
  2. C:\TEST\WF\FOLDER2\WF.txt
  3. C:\TEST\WF\FOLDER3\WF.txt

Expected output

  1. C:\TEST\WF\FOLDER1\FOLDER1.txt
  2. C:\TEST\WF\FOLDER2\FOLDER2.txt
  3. C:\TEST\WF\FOLDER3\FOLDER3.txt

    @echo off
    setlocal EnableDelayedExpansion
    for /d %%F in (C:\TEST\WF\*) do (
        for %%* in (%%F) do set CurrDirName=%%*
        IF EXIST "%%F\*.dat" (REN "%%F\*.dat" %CurrDirName%.txt)
        )
    
John G
  • 23
  • 3
  • 11

0 Answers0