#1 2019-09-14 22:12

Asimetron
Member
Registered: 2019-09-14
Posts: 4

Rename folders according to their level in the windows tree

Hi good day.
First of all a greeting and thank you very much for continuing to offer your excellent effort and program in free version, I am making an effort to buy the most complete version.

I would like you to help me rename some folders with the following folder structure:

\ Libraries \ Rooms \ Area \ Books

EXAMPLE

B: Libraries
\ Library of Studies \ Information Room \ Excell Area \ Course Book
\ Study Library \ Computer Room \ Word Area \ Practice Book
\ Business Library \ Finance Room \ Accounting Area \ Payment Book
\ Business Library \ Finance Room \ Client Area \ Quotation Book
\ Computer Library \ Program Room \ Renamer Area \ Book of Expressions

The only thing I need to rename is the keyword that defines the function of each level of the folders:

Imagine entering a library:

B: Libraries
\ Libraries
\Rooms
\Area
\Books

I know that with the common rules it can be done, but what I am looking for is a way to do it automatically according to the level of the folder, that is.

All level 1 folders.
Remove the first word from its name and replace it with "Libraries."

All level 2 folders.
Remove the first word from its name and replace it with "Rooms."

All level 3 folders.
Remove the first word from its name and replace it with "Area".

All level 4 folders.
Remove the first word from its name and replace it with "Books."

Unfortunately I don't know anything about scripts and very little about regular expressions, but for goodness sake, I'm able to understand them once I see them.

Thank you very much for your help.


ESPAÑOL
Renombrar carpetas segun su nivel en el arbol de windows

Hola, buen dia.
Antes que nada un saludo y muchas gracias por seguir ofreciendo tu excelente esfuerzo y programa en versión gratuita, estoy haciendo un esfuerzo para comprar la versión mas completa.

Quisiera que por favor usted me ayudara a renombrar unas carpetas con la siguiente estructura de carpetas:

\Bibliotecas\Salas\Área\Libros

EJEMPLO

B:Bibliotecas
\Biblioteca de Estudios\Sala de Informatica\Área de Excell\Libro de Cursos
\Biblioteca de Estudios\Sala de Informatica\Área de Word\Libro de Practicas
\Biblioteca de Empresas\Sala de Finanzas\Área de Contabilidad\Libro de Pagos
\Biblioteca de Empresas\Sala de Finanzas\Área de Cientes\Libro de Cotizaciones
\Biblioteca de Computo\Sala de Programas\Área de Renamer\Libro de Expresiones

Lo unico que necesito renombrar es la palabra clave que define la funcion de cada nivel de las carpetas:

Imagina que entras a una biblioteca:

B:Bibliotecas
\Bibliotecas
\Salas
\Área
\Libros

Se que con las reglas comunes se puede hacer, pero lo que busco es una manera de hacerlo automaticamente segun el nivel de la carpeta, es decir.

Todas las carpetas de nivel 1.
Elimina la primera palabra de su nombre y reemplazala por "Bibliotecas".

Todas las carpetas de nivel 2.
Elimina la primera palabra de su nombre y reemplazala por "Salas".

Todas las carpetas de nivel 3.
Elimina la primera palabra de su nombre y reemplazala por "Área".

Todas las carpetas de nivel 4. 
Elimina la primera palabra de su nombre y reemplazala por "Libros".

Desafortunadamente no se nada acerca de los scripts y muy poco de las expresiones regulares, pero por amor de dios, soy habil entendiendolos una ves que los veo.

Muchas gracias por tu ayuda.

Offline

#2 2019-09-15 09:20

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename folders according to their level in the windows tree

Hi and welcome.


You want to rename folders according to there level in the folder hierarchic structure

FROM:
B: Libraries
\ Library of Studies \ Information Room \ Excell Area \ Course Book
\ Study Library \ Computer Room \ Word Area \ Practice Book
\ Business Library \ Finance Room \ Accounting Area \ Payment Book
\ Business Library \ Finance Room \ Client Area \ Quotation Book
\ Computer Library \ Program Room \ Renamer Area \ Book of Expressions

TO:
B: Libraries
\ Libraries. of Studies \ Rooms. Room \ Area Area \ Books. Book
\ Libraries. Library \ Rooms. Room \ Area Area \ Books. Book
\ Libraries. Library \ Rooms. Room \ Area Area \ Books. Book
\ Libraries. Library \ Rooms. Room \ Area Area \ Books. Book
\ Libraries. Library \ Rooms. Room \ Area Area \ Books. of Expressions


?


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#3 2019-09-15 10:44

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,440

Re: Rename folders according to their level in the windows tree

I think the translated example is a bit misleading, because the order of words changes when switching from Spanish to English language.

For example, "Biblioteca de Empresas" in Spanish converts to "Business Library" in English, so replacing the first word no longer makes sense.

So, considering the original example in Spanish...

\Biblioteca de Estudios\Sala de Informatica\Área de Excell\Libro de Cursos
\Biblioteca de Estudios\Sala de Informatica\Área de Word\Libro de Practicas
\Biblioteca de Empresas\Sala de Finanzas\Área de Contabilidad\Libro de Pagos
\Biblioteca de Empresas\Sala de Finanzas\Área de Cientes\Libro de Cotizaciones
\Biblioteca de Computo\Sala de Programas\Área de Renamer\Libro de Expresiones

The desired result looks like this?

\Bibliotecas de Estudios\Salas de Informatica\Área de Excell\Libros de Cursos
\Bibliotecas de Estudios\Salas de Informatica\Área de Word\Libros de Practicas
\Bibliotecas de Empresas\Salas de Finanzas\Área de Contabilidad\Libros de Pagos
\Bibliotecas de Empresas\Salas de Finanzas\Área de Cientes\Libros de Cotizaciones
\Bibliotecas de Computo\Salas de Programas\Área de Renamer\Libros de Expresiones

Essentially, replacing "Biblioteca" › "Bibliotecas", "Sala" › "Salas", "Libro" › "Libros" ?

If this is not what you want, can you please provide a complete example of input and desired output file paths?

Offline

#4 2019-09-15 10:56

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename folders according to their level in the windows tree

Test script: Change first word of a folder depending on its level in the folder hierarchy.


-- TEST with a small set of folders only (only five or so) due to pop-up message in script.
( you can disable the "showmessage()" lines by comment them out by prefixing the lines by '//' )

-- And have a BACKUP.

1. Add Folders
and use Filter Settings >> "Add Folders as files" AND "Include Subfolders"

2. Add the Path column (*see EDIT-1 below) to the file list and sort PATH upside down (deepest to top most) 
X:\Top\sub1\Sub2
X:\Top\sub1
X:\Top

3. Add the below script (*see EDIT-2 below)
(Help at: http://www.den4b.com/wiki/ReNamer:Rules:PascalScript)

4. Adjust the user settings in the script as wanted.

5. Press [Preview], read the messages, see NewName column, maybe perform a test rename

6. If it works fine, copy the "// BLOCK" in the script to how many renaming rules you want and adjust the user settings

HTH?

////Usage: Change first word of a folder depending on its level in the folder hierarchy.
////Found at: http://www.den4b.com/forum/viewtopic.php?pid=11025#p11025
////1. Add Folders >> Filter Settings >> "Add Folders as files" AND "Include Subfolders"
////2. Sort PATH upside down (deepest to top most)

var
  SubFolders:TWideStringArray;
  currDirName,NewWord:WideString;
  Level:Integer;

begin
  ////WideSplitString(const Input, Delimiter: WideString): TWideStringArray;
  SubFolders := WideSplitString(FilePath, '\');

  ////Check at which level number you want to rename:
 //// (The correct level depends on your top level start folder and if we count the drive letter too or not)
  showmessage( 'Path: '+FilePath+#13#10+IntToStr(length(SubFolders)) );


////=======================BLOCK START    (copy this block and adjust user settings as need:
////------  User Setting:
//// If Level deep is '3', change first word of folder name to 'TEST'
Level := 3;
NewWord := 'TEST';
////------ The Code:
If (length(SubFolders)=Level)  Then
    begin
      currDirName := SubFolders[Level-1];
      ////ReplaceRegEx(Input, Find, Replace; CaseSensitive, UseSubstitution): WideString;
      FileName := ReplaceRegEx(FileName,'^.+?\b',NewWord,false,false);

      showmessage('Path: '+FilePath
             +#13#10+'Path Len: '+IntToStr(length(SubFolders))
             +#13#10+'Wanted Level: '+IntToStr(Level)
             +#13#10+'Rename from: '+currDirName
             +#13#10+'To         : '+FileName);
    end;
////=======================BLOCK END

end.




- - - *EDIT-1

I learned smtg new:


ReNamer 5.60  (13 September 2011)
* Added explicit option to sort by path in reverse order for renaming folders;

See on top of the file list: Option >> Sort by path for renaming folders



- - - *EDIT-2


I have found an issue as this script also want to rename files also.


Try to change
SubFolders := WideSplitString(FilePath), '\'); //work on path\filename
and every
If (length(SubFolders)=Level) Then


To
SubFolders := WideSplitString(WideExtractFileDir( FilePath ), '\');/ //work only on the path
and
If (length(SubFolders)=Level) and (WideDirectoryExists(FileName)) Then ///Is Level AND Is a dir, no file




(Find me: sort path, order path, deepest to top)

Last edited by Stefan (2019-09-20 10:48)


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#5 2019-09-19 06:51

Asimetron
Member
Registered: 2019-09-14
Posts: 4

Re: Rename folders according to their level in the windows tree

I have divided my computer into multiple partitions according to file types.

"D:\Bibliotecas"                 contains only text.
"E:\Cinemas"                    video only.
"F:\Galerías"                     only images.

So I need to restructure my folders according to the model used in each partition.
This is exactly what I need.

Den4b wrote:

D\Bibliotecas
\Biblioteca de Estudios\Sala de Informatica\Área de Excell\Libro de Cursos
\Biblioteca de Estudios\Sala de Informatica\Área de Word\Libro de Practicas
\Biblioteca de Empresas\Sala de Finanzas\Área de Contabilidad\Libro de Pagos
\Biblioteca de Empresas\Sala de Finanzas\Área de Cientes\Libro de Cotizaciones
\Biblioteca de Computo\Sala de Programas\Área de Renamer\Libro de Expresiones

Den4b wrote:

The desired result looks like this?

Den4b wrote:

E\Cinemas
\Cinemas de Estudios\Salon de Informatica\Proyector de Excell\Catalogos de Cursos
\Cinemas de Estudios\Salon de Informatica\Proyector de Word\Catalogos de Practicas
\Cinemas de Empresas\Salon de Finanzas\Proyector de Contabilidad\Catalogos de Pagos
\Cinemas de Empresas\Salon de Finanzas\Proyector de Cientes\Catalogos de Cotizaciones
\Cinemas de Computo\Salon de Programas\Proyector de Renamer\Catalogos de Expresiones

Essentially replace the folders, only the first word, with any word that helps me in my classification.

D:\BIBLIOTECAS    E:\CINEMAS      F:\GALERÍAS        FOLDER LEVEL 1
"Biblioteca"                "Cinema"              "Galería"              Folder Level 2     
"Sala"                       "Salon"                 "Sala"                  Folder Level 3
"Área"                       "Proyector"           "Área"                  Folder Level 4
"Libro"                      "Catalogos"           "Sección"              Folder Level 5

Offline

#6 2019-09-19 07:10

Asimetron
Member
Registered: 2019-09-14
Posts: 4

Re: Rename folders according to their level in the windows tree

Pascal's script is excellent, it is exactly what I am looking for, I have tested it and it renames me the level 4 and 5 folders, but in the following ones it marks me "Access denied"

The folder has security permissions set correctly, so I don't understand what I'm doing wrong.

Tap the script a bit to remove the message box that appears since I don't need it.
But as I said, I am not a programmer and maybe I made a mistake.

I leave the modified script, the folder names are not relevant at this time, because I will change them according to my needs.

Thank you very much for your help.
God bless you for that.

I am contemplating buying the program because for years it has served me a lot and it is fair that you receive something for your effort.


Stefan wrote:

Test script: Change first word of a folder depending on its level in the folder hierarchy.

////Usage: Change first word of a folder depending on its level in the folder hierarchy.
////Found at: http://www.den4b.com/forum/viewtopic.php?pid=11025#p11025
////1. Add Folders >> Filter Settings >> "Add Folders as files" AND "Include Subfolders"
////2. Sort PATH upside down (deepest to top most)

var
  SubFolders:TWideStringArray;
  currDirName,NewWord:WideString;
  Level:Integer;

begin
////WideSplitString(const Input, Delimiter: WideString): TWideStringArray;
SubFolders := WideSplitString(FilePath, '\');

////Check at which level number you want to rename:
//// (The correct level depends on your top level start folder and if we count the drive letter too or not)

////Carpetas de nivel 3 - Sala
////=======================BLOCK START
////------  User Setting:
//// If Level deep is '3', change first word of folder name to 'Sala'
Level := 3;
NewWord := 'Sala';
////------ The Code:
If (length(SubFolders)=Level)  Then
    begin
      currDirName := SubFolders[Level-1];
      ////ReplaceRegEx(Input, Find, Replace; CaseSensitive, UseSubstitution): WideString;
      FileName := ReplaceRegEx(FileName,'^.+?\b',NewWord,false,false);
    end;
////=======================BLOCK END

////Carpetas de nivel 4 - Area
////=======================BLOCK START
////------  User Setting:
//// If Level deep is '4', change first word of folder name to 'Area'
Level := 4;
NewWord := 'Area';
////------ The Code:
If (length(SubFolders)=Level)  Then
    begin
      currDirName := SubFolders[Level-1];
      ////ReplaceRegEx(Input, Find, Replace; CaseSensitive, UseSubstitution): WideString;
      FileName := ReplaceRegEx(FileName,'^.+?\b',NewWord,false,false);
    end;
////=======================BLOCK END

////Carpetas de nivel 5 - Proyector
////=======================BLOCK START
////------  User Setting:
//// If Level deep is '5', change first word of folder name to 'Proyector'
Level := 5;
NewWord := 'Proyector';
////------ The Code:
If (length(SubFolders)=Level)  Then
    begin
      currDirName := SubFolders[Level-1];
      ////ReplaceRegEx(Input, Find, Replace; CaseSensitive, UseSubstitution): WideString;
      FileName := ReplaceRegEx(FileName,'^.+?\b',NewWord,false,false);
    end;
////=======================BLOCK END

////Carpetas de nivel 6 - Catalogo
////=======================BLOCK START
////------  User Setting:
//// If Level deep is '6', change first word of folder name to 'Catalogo'
Level := 6;
NewWord := 'Catalogo';
////------ The Code:
If (length(SubFolders)=Level)  Then
    begin
      currDirName := SubFolders[Level-1];
      ////ReplaceRegEx(Input, Find, Replace; CaseSensitive, UseSubstitution): WideString;
      FileName := ReplaceRegEx(FileName,'^.+?\b',NewWord,false,false);
    end;
////=======================BLOCK END
end.

    DUED

Stefan wrote:

1. Add Folders
and use Filter Settings >> "Add Folders as files" AND "Include Subfolders"

2. Add the Path column (*see EDIT below) to the file list and sort PATH upside down (deepest to top most)
X:\Top\sub1\Sub2
X:\Top\sub1
X:\Top

3. Add the below script
4. Adjust the user settings in the script as wanted.
5. Press [Preview], read the messages, see NewName column, maybe perform a test rename
6. If it works fine, copy the "// BLOCK" in the script to how many renaming rules you want and adjust the user settings

Offline

#7 2019-09-19 18:33

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Rename folders according to their level in the windows tree

Asimetron wrote:

Pascal's script is excellent, it is exactly what I am looking for, I have tested it and it renames me the level 4 and 5 folders, but in the following ones it marks me "Access denied"

The folder has security permissions set correctly, so I don't understand what I'm doing wrong.


Your script works for me.
But I have found an issue as it also want to rename files also.


Try to change
SubFolders := WideSplitString(FilePath), '\'); //work on path\filename
and every
If (length(SubFolders)=Level) Then


To
SubFolders := WideSplitString(WideExtractFileDir( FilePath ), '\'); //work only on the path
and
If (length(SubFolders)=Level) and (WideDirectoryExists(FileName)) Then //Is Level AND Is a dir, no file




HTH?


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#8 2019-09-20 18:51

Asimetron
Member
Registered: 2019-09-14
Posts: 4

Re: Rename folders according to their level in the windows tree

It does not work

Stefan wrote:

To
SubFolders := WideSplitString(WideExtractFileDir( FilePath ), '\'); //work only on the path
and
If (length(SubFolders)=Level) and (WideDirectoryExists(FileName)) Then //Is Level AND Is a dir, no file

Offline

#9 2019-09-24 11:55

Cleoss
Member
Registered: 2018-01-19
Posts: 17

Re: Rename folders according to their level in the windows tree

Stefan wrote:
3. Add the below script (*see EDIT-2 below)
(Help at: [url]http://www.den4b.com/wiki/ReNamer:Rules:PascalScript)[/url]

Sorry for my correction, but one bracket lies up inside an url tag so it's leading to an absent wiki page instead of:

(Help at: [url]http://www.den4b.com/wiki/ReNamer:Rules:PascalScript[/url])

Offline

Board footer

Powered by FluxBB