1.

Solve : I want to rename folders?

Answer»

I have a long list of folders in the same dir, which I want to rename.
They are all called:

001_files
002_files
003_files
and so on

I want to remove the "_files", so the result would be

001
002
003
and so on

And to those who might ask... - yes, its folders from saved webpages

I was thinking that a batch file might do the trick, but I dont know much about batch files... maybe someone could help me out ??Run this from the directory which contains the folders you want to rename:
CODE: [Select]
@echo off
for /f "tokens=1-2 delims=_ " %%a in ('dir /b /a:d') do (
ren %%a_%%b %%a
)

Hope this helps. Thank you very much... though it didn't rename all of the folders.
The folders with spaces in them, didnt get renamed! Like:

"001_files" was a success - it was renamed to "001"

But "0 02_files" (space between the zeros!) didnt get renamed!

Can you somehow fix that, or can I do it myself?Gee! I must have missed that part about the embedded spaces. :-/

Code: [Select]
@echo off
for /f "tokens=1-3 delims=_ " %%a in ('dir "? *_files" /b /a:d') do (
ren "%%a %%b_%%c" %%a%%b
)


Run from the same directory as last time.

Hope this helps. The new batch doesn't seem to work. Nothing happens... maybe it would be easier for you if I wrote some of the folders real names:

These are the ones which were rename with the first batch:
From:
Djuulie.1_files
Ea_files
Ea2_files

To:
Djuulie.1
Ea
Ea2

Nothing happens to these folders:
_girlism_1_files
-Mizz single-1_files
hotte 1_files
LasDulle 1_files
Sabber 1_files

If you need any other info to make batch, please just ask... thank you very much for helping me out Batch files are written for specific purposes and generally HANDLE the incoming data based on a particular format or pattern.

First you posted the folders were all named 001_files, 002_files, 003_files etc. I responded with an answer that covered the situation.

Then out of left FIELD you posted that there were embedded spaces in the folder names (ie. 0 01_files, 0 02_files, 0 03_ files). Again I responded with an answer that covered the situation.

Now you've posted that in addition to embedded spaces, there are also special symbols in the folder names.

Since I have no idea what bombshell is coming next, I suggest you WRITE a script where you can inspect the data and sort out any eventuality.

Good luck. Well I'm sorry for not being specific enough... I'm pretty new to it, and didn't know how much info you needed.

Anyways, I'm thankful for the help you have given me

If there's more soul savers out there.. please help me out... and please ask for more info, if you need it This will work in most cases. Caution: if there are multiple underscores in a directory name RESULTS will be unpredicatable since the underscore is the delimiter for the for statement.

Code: [Select]
@echo off
for /f "tokens=1-2 delims=_" %%a in ('dir /b /a:d') do (
ren "%%a_%%b" "%%a"
)


A script really would be better for this.

Thank you very much for all your help.
The once with more underscores I will just rename manually - np



Discussion

No Comment Found