Computing.Net > Forums > Programming > Folder rename wildcard question

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Folder rename wildcard question

Reply to Message Icon

Name: Wireworld
Date: October 2, 2009 at 06:32:06 Pacific
OS: Windows XP
Subcategory: Batch
Tags: wildcard. batch, folder
Comment:

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 UK1012001PC49

sometimes 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



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: October 2, 2009 at 09:57:52 Pacific
Reply:

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
  )
)


2

Response Number 2
Name: Wireworld
Date: October 2, 2009 at 10:37:12 Pacific
Reply:

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=wireworld

for /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


2

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


RunTime Error 424 Object ... for /f tokens and delims ...


Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: Folder rename wildcard question

Prompt folder rename www.computing.net/answers/programming/prompt-folder-rename/16248.html

selective recursive folder renaming www.computing.net/answers/programming/selective-recursive-folder-renaming/9617.html

Bacth file to rename the DRM folder www.computing.net/answers/programming/bacth-file-to-rename-the-drm-folder/16823.html