Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have multiple files in a DIR with one common extension .f. I have to do 3 things.
1) I have to partly rename the file
EX: If the file name is 0104_184934604_C529400896.f then i have to change it to C529400896.f.2) The i have to erase a content inside the file:
EX: If i have
1
2
3
4
BEGINThen i have to search for the begin word and erase everything above it,
3) I have a common text in all the files and i have to replace with a New text
EX: I have to find this common text {{Findme}} and replace with {{Replace Me}}Im a novice when it comes to scripting.
I would prefer to do this using a batchfile and any help would be greatly appreciated.
Please...............Thanks
GT

Hi Guru
I forgot to ask if the filename(s) are the same format
ie. If the file name is 0104_184934604_C529400896.f then i have to change it to C529400896.f.Is there always underlines in the filenames or to make it easier to write is the C529400896 always the same length.
Both are OK.

Hi Dtech10,
Yes, The file names are in the same format and and same length with Underscores. The only Constant value would be C5.
And
Yes, The length of values on the renamed files are always the same: For example:
Original File Name: 0104_184934604_C529400896.f
Renamed File should look like this: C529400896.fHere is what i have so far:
@echo off
Title Que To Toll-Free
cd C:\testing\Q2F
echo Re-sending files to QueToTollFree
echo.
echo Listing all *.nt2 files
DIR
echo.
echo Copying files to Archive
copy /Y *.nt2 C:\testing\Q2F\Archive
echo.
echo Renaming files to *.F
ren *.nt2 *.F
echo.
echo.
echo Renaming files to C5
call renamer.bat
echo.
echo.
echo Changing file content (Yet to be implemented)
PauseAs you can see above i'm calling another batchfile called renamer.bat which looks like this:
@echo off:main
for %%F in (*.f) do call :renamer %%F
goto :eof:renamer
set old=%1
ren %1 %old:~-12%
:: endLet me know if you have any questions. and thank you for looking into this.
Guru
GT

Hi Guru
Try this.
@echo off
SetLocal EnableDelayedExpansiondir /b *.f | find "_" > Files.txt
for /f "tokens=1-3 delims=_" %%a in (Files.txt) do (
set OrgName=%%a_%%b_%%c
set NewName=%%c
ren !OrgName! !NewName!
)
set Flag=0
dir /b *.f > Files.txt
for /f "tokens=* delims=" %%a in (Files.txt) do (
set Flag=0
for /f "tokens=* delims=" %%b in (%%a) do (
set Line=%%b
if "!Line!" EQU "BEGIN" (set Flag=1)
if !Flag! EQU 1 (echo %%b >> Tmp.txt)
)
del %%a
ren Tmp.txt %%a
)
del Files.txt
exit /b

Hello Dtech10,
Thanks a lot for your reply and script. It worked. I have made some minor changes to suit my system settings and dir settings.
Once again thanks a lot
Regards,
Guru

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |