HITC
asked on
Rename Script - File in folder gets same name as folder
Hi,
I need a script or a handy application that can help me with this.
I have 400 folders - all folders has the correct name - In every folder i got 1 file.
I want this file to get the same name as the folder its placed in.
Exampel
Foldername ;
"Stew - High"
The file inside should then be ;
"Stew - High" + extension.
Thank you in advice
I need a script or a handy application that can help me with this.
I have 400 folders - all folders has the correct name - In every folder i got 1 file.
I want this file to get the same name as the folder its placed in.
Exampel
Foldername ;
"Stew - High"
The file inside should then be ;
"Stew - High" + extension.
Thank you in advice
ASKER
Hmm.
Dosent work.
I get en error ;
"do was unexpected at this time."
Have created it like a CMD file.
Dosent work.
I get en error ;
"do was unexpected at this time."
Have created it like a CMD file.
open cmd.exe, and launch that code line.
ASKER
Well somthing is wrong :) - Sorry
Can you figure it out ?
Thank you
Can you figure it out ?
Thank you
ASKER
Attached file
CMD.png
CMD.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Though that works, it is bad style (because it uses a bug's side effect). The double quotes should always enclose the whole path. It is always a good idea to make sure the FOR variable does not already contain the enclosing double quotes, too.
I would also make sure only folders are retrieved by the DIR.
I would also make sure only folders are retrieved by the DIR.
for /f "delims=" %a in ('dir /b /a:d c:\users\jje\desktop\test') do ren "c:\users\jje\desktop\test\%~a\*.*" "%~a.*"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! It works.
I used Qlemo's powershell script!
I am a bit unsure who to give the point. McKnife gave the correct answer i think.
I used Qlemo's powershell script!
I am a bit unsure who to give the point. McKnife gave the correct answer i think.
Usually you accept the answer you used and/or are certain it works. However, you might accept both solutions and split the points, equally or not. Both solutions are worth the same IMHO.
Qlemo, I don't mind if you call it bad style. If there would be cases where it would lead to unwanted results, I would like to see those so I could learn from it. If there were files at the same level as the folders, it would not lead to unwanted results, nor would the variable already contain enclosing double quotes - if I don't see it, please help me with an example.
The points don't matter to me.
The points don't matter to me.
Files in the root folder lead to an error message, if I'm correct (didn't test yet).
One reason for not to enclose parts of the path only in double quotes is that you then need to enclose each part individually...
One reason for not to enclose parts of the path only in double quotes is that you then need to enclose each part individually...
ASKER
Thank you!
Points are splitted
Points are splitted
Open in new window
This assumes the 400 folders are below c:\test.