How to rename a file to its parent folder name?

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
rolandd
Senior Member
Senior Member
Posts: 313
Joined: 2003-06-26, 09:02 UTC
Location: Indonesia
Contact:

How to rename a file to its parent folder name?

Post by *rolandd »

Hey guys,

The question is very simple: How to rename a file to its parent folder name?

The situation is as follows: I have just over 150 folders with each 1 file in it. Now, these single files have random names. So I want to rename them to the name of the folder they are in as they represent articles.

Searching through the posts I have found several posts where people want to rename but not a situation like this. Also the MRT I could not figure out how to do this. Nor in combination with a plugin.

Am I missing the obvious or is it not that simple?

Regards,

RolandD
Registered user #92105
User avatar
Sombra
Power Member
Power Member
Posts: 814
Joined: 2005-12-27, 22:23 UTC
Location: Zaragoza, Spain

Post by *Sombra »

You can press CTRL+B for Branch view mode, later select the files, go to the MRT. Now at Rename mask filename: try to put [P] - name of the parent directory -
Also you can put [G][C] - Grandparent directory -
I can read English, but... I write like Tarzan. (sorry)
User avatar
majkinetor !
Power Member
Power Member
Posts: 1580
Joined: 2006-01-18, 07:56 UTC
Contact:

Post by *majkinetor ! »

U can to do it via batch.

In single folder u use:

Code: Select all

::get the file name
dir /b > out
set /P F=<out

::get the dir name
for /F "tokens=*" %%I in ("%CD%") do set D=%%~nI

::rename
ren %F% %D%
This will rename the file in one concrete folder to match its parent name.

You then call this script for eatch folder using for /R command

EDIT: but sombra did it much easier. I didn't know about [p]
Habemus majkam!
rolandd
Senior Member
Senior Member
Posts: 313
Joined: 2003-06-26, 09:02 UTC
Location: Indonesia
Contact:

Post by *rolandd »

2Sombra
Thanks for the very fast reply. I guess besides trying the MRT and searching the forums I should RTFM :P
Registered user #92105
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

[mod]OT posts moved to [OT] Quarrels.

Hacker (Moderator)[/mod]
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
Post Reply