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:
- C:\TEST\WF\FOLDER1\FILE.dat
- C:\TEST\WF\FOLDER2\FILE.dat
- C:\TEST\WF\FOLDER3\FILE.dat
Current output:
- C:\TEST\WF\FOLDER1\WF.txt
- C:\TEST\WF\FOLDER2\WF.txt
- C:\TEST\WF\FOLDER3\WF.txt
Expected output
- C:\TEST\WF\FOLDER1\FOLDER1.txt
- C:\TEST\WF\FOLDER2\FOLDER2.txt
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) )