Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi I have a folder which contains a text file called wireworld.txt. I would like a batch file that can check for the txt file and if it finds it rename the folder to that name, e.g wireworld. The wireworld name can be set in the batch, it doesn't need to read it from the txt file.
The only snag is that the folder has a changing name. It always starts off with UK1012001PC and can have any two numbers on the end.
Example UK1012001PC36
or UK1012001PC49sometimes there can be 3 or more UK1012001PC** folders, but only one folder will have the wireworld.txt in it. Could the batch file delete the UK101200PC** folders without the wireworld.txt.
Thanks
Mac

Try this (untested):
setlocal rem Set up these variables as appropriate set filename=wireworld.txt set folder_old_pattern=UK1012001PC?? set folder_new_name=wireworld for /d %%d in (%folder_old_pattern%) do ( if exist %%d\%filename% ( ren %%d %folder_new_name% ) else ( rd /s %%d ) )

Thank you so much, it works like a charm.
I added /q to the last line so It doesn't ask me to confirm:
setlocal
rem Set up these variables as appropriate
set filename=wireworld.txt
set folder_old_pattern=UK1012001PC??
set folder_new_name=wireworldfor /d %%d in (%folder_old_pattern%) do (
if exist %%d\%filename% (
ren %%d %folder_new_name%
) else (
rd /q /s %%d
)
)Many, many thanks and my kindest regards to you
Mac

![]() |
RunTime Error 424 Object ...
|
for /f tokens and delims ...
|
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |