#1 2014-08-28 09:43

Daredee
Member
Registered: 2014-08-28
Posts: 3

Looking for script - rename folders to number of files inside

Может кто писал такой, нужно чтобы папки переименовались в количество файлов внутри, а если количества совпадают, то, например, букву добавляло после числа

ps ничего, что по-русски?

Last edited by Daredee (2014-08-28 10:10)

Offline

#2 2014-08-28 14:41

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

Re: Looking for script - rename folders to number of files inside

>>>Может кто писал такой, нужно чтобы папки переименовались в количество файлов внутри,

Попробуйте это
- Проверка фильтр
--- Не включать файлы
--- Для добавления папок в виде файлов
- Добавить папки
- Использовать этот скрипт ниже

>>>Can someone wrote this, need to renamed folder with the number of files inside,

Try this
- Check the filter:
--- to not include files
--- to add a folder as a file
- Add Folder
- Use this script below

Example:
FROM:
\foldername (with 6 files inside)
TO:
\foldername_(6 Files)

Code: scan folders for amount of files inside, then rename the folder to add that ascertained number.

var 
  Filesarray:TStringsArray;
begin
  SetLength(Filesarray, 0); //start with zero for each next file/folder to process.

                     //Folder , array var ,  Recurse?, Hidden?, System?, mask
  WideScanDirForFiles(FilePath, Filesarray,  False,    False ,  False ,   '*' );

  FileName := FileName + '_(' + IntToStr(length(Filesarray)) + ' Files)';
end.

How to use >> http://www.den4b.com/wiki/ReNamer:Rules:PascalScript




Infos: >> http://www.den4b.com/wiki/ReNamer:Pasca … Management

// WideScanDirForFiles(Dir: WideString; var Files: TStringsArray; const Recursive, IncludeHidden, IncludeSystem: Boolean; const Mask: WideString); 	
// You can get a list of the files inside a folder.
//     Dir:           The folder you want to scan.
//     Files:         A TStringsArray var to store the list of files.
//     Recursive:     scan the subfolders?
//     IncludeHidden: list the hidden files?
//     IncludeSystem: list the system files?
//     Mask:          list everything '*', or e.g. '*.txt'


>>>а если количества совпадают, то, например, букву добавляло после числа

Смотреть варианты
Options > Fix conflicting new names



>>>ps ничего, что по-русски?
Yes, wait for "den4b"



- - -
EDIT:
Sorry, I forgot about clearing the var for each iteration as den4b does below by setting it to zero.
That's why Daredee got that wrongly result. So I added """SetLength(Filesarray, 0);""" NOW too.



 

Last edited by Stefan (2014-08-29 06:50)


Please see HELP and MANUAL in Wiki for more info.
If ReNamer had helped you, please donate a coin to Denis or buy a Pro license for commercial use. (Lite vs Pro)

Offline

#3 2014-08-28 15:43

Daredee
Member
Registered: 2014-08-28
Posts: 3

Re: Looking for script - rename folders to number of files inside

Thanks alot!

Stefan wrote:

- Использовать этот скрипт ниже

How to reset counter after each dir?
Now I'm getting something like Dir1_(1 Files), Dir2_(4 Files), Dir3_(11 Files), Dir4_(13 Files) and so on but I need to rename it like Dir1_(1 Files), Dir2_(3 Files), Dir3_(7 Files), Dir4_(2 Files)

Last edited by Daredee (2014-08-28 15:44)

Offline

#4 2014-08-28 16:38

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

Re: Looking for script - rename folders to number of files inside

A small variation of Stefan's script which will reset counter for every directory and change new name only if it's a directory.

var
  Files: TStringsArray;
begin
  if WideDirectoryExists(FilePath) then
  begin
    SetLength(Files, 0);
    WideScanDirForFiles(FilePath, Files, False, False, False, '*');
    FileName := FileName + ' (' + IntToStr(Length(Files)) + ' Files)';
  end;
end.

P.S. Да, можно и по-русски, но здесь большая часть говорит на английском.

Offline

#5 2014-08-28 20:51

Daredee
Member
Registered: 2014-08-28
Posts: 3

Re: Looking for script - rename folders to number of files inside

works great, thank you

Offline

Board footer

Powered by FluxBB