I have outputted some text files all in the same directory. Each .txt file has within a group number, this number always starts with RXC and can go upwards of 5 characters afterwards, giving us RXCXXXXX i need the script to find this RXC number and rename the file to its corresponding group number, then do the same for all files in the same directory.
Thanks in advance,
Joe
.bat or .vbs Find within text and Rename File
Moderator: DosItHelp
-
- Expert
- Posts: 442
- Joined: 01 Aug 2010 17:13
- Location: Canadian Pacific
- Contact:
Re: .bat or .vbs Find within text and Rename File
You don't need to make a new thread for each step of whatever it is you require, you could just ask more questions in one thread. But at least you detail your questions.
If RXC#~ is always at the beginning of a line,
Change C:\...\Target Folder.
Edit: Oops, toggles always mess me up. Fixed.
If RXC#~ is always at the beginning of a line,
Code: Select all
setlocal enabledelayedexpansion
set toggle=0
for %%x in ("C:\...\Target Folder\*.txt") do (
for /f "usebackq delims=" %%y in ("%%x") do (
if !toggle!==0 (
set "line=%%y"
if "!line:~0,3!"=="RXC" ren "%%x" "%%y.txt"&set toggle=1
)
)
set toggle=0
)
Change C:\...\Target Folder.
Edit: Oops, toggles always mess me up. Fixed.