Autor Beitrag
bobby
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 25

Win XP
D7 Prof
BeitragVerfasst: Do 20.05.04 11:04 
First, I apologize that I don't write in German, I hope that isn't a big problem... :(

I'm making an application that needs Multi-rename tool. To be more accurate, the user have to chose one folder and this tool needs to rename all subfolders and files to uppercase, eventualy there can be options to set if just folder names to be uppercased etc...
Here is the screenshot of what I'm doing:
members.chello.at/bobby100/img/gui1.jpg
Take a look at upper-right corner, the Change case function isn't implemented...

Now, I must admit that I don't even have idea how to search for subfolders and files in subfolders.
If someone can tell me how, or to give me a proper advice, or to write that code for me, I'll apreciate that a lot.

Application is freeware, and it will be distributed under GPL
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 20.05.04 11:40 
hi and welcome to the DF !!
here is the code to serach files in subfolders: www.delphi-forum.de/viewtopic.php?t=94

_________________
In the beginning was the word.
And the word was content-type: text/plain.
bobby Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 25

Win XP
D7 Prof
BeitragVerfasst: Sa 22.05.04 00:04 
Thanks a lot, I did it :)
Here are the functions and procedures I used, I hope they can help someone:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
procedure RenameDir(DirFrom, DirTo: string); 
var 
  shellinfo: TSHFileOpStruct; 
begin 
  with shellinfo do 
  begin 
    Wnd    := 0; 
    wFunc  := FO_RENAME; 
    pFrom  := PChar(DirFrom); 
    pTo    := PChar(DirTo);
    {fFlags := FOF_FILESONLY or FOF_ALLOWUNDO or
              FOF_SILENT or FOF_NOCONFIRMATION;}

    fFlags := FOF_ALLOWUNDO or
              FOF_SILENT or FOF_NOCONFIRMATION;
  end;
  SHFileOperation(shellinfo);
end;


function FindFiles(Directory: string; InclAttr, ExclAttr: Integer;
const SubDirs: Boolean; const Files: TStrings): Integer;
var
  SearchRec: TSearchRec;
begin
  Directory := IncludeTrailingPathDelimiter(Directory);
  FillChar(SearchRec, SizeOf(SearchRec), 0);
  if FindFirst(Directory + '*.*', faAnyFile, SearchRec) = 0 then
  begin
    try
      repeat
        if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
          if ((SearchRec.Attr and InclAttr > 0) or ((SearchRec.Attr = 0) and (InclAttr <> faDirectory))) and
               (SearchRec.Attr and ExclAttr = 0) then
          begin
            Files.Add(Directory + SearchRec.Name);
            if SubDirs then
              if SearchRec.Attr and faDirectory <> 0 then
                FindFiles(Directory + SearchRec.Name, InclAttr, ExclAttr, SubDirs, Files);
          end;
      until
        FindNext(SearchRec) <> 0;
    finally
      FindClose(SearchRec);
    end;
  end;
  Result := Files.Count;
end;

procedure Trenamer_form.Button1Click(Sender: TObject); // Find 
var
  sl: TStringList;
  include: integer;
  exclude: integer;
  subfolders: boolean;
  rootfolder: string;

begin
include := 0;
exclude := 0;
subfolders := false;
rootfolder := ShellTreeView1.path;
 if  checkbox1.Checked = true then  // include root folder in ListBox1
  begin
    Listbox1.Items.Add(rootfolder);
    include := faDirectory;
  end;
 if  checkbox2.Checked = true then include := include or faAnyFile; // include files in folders
 if  checkbox3.Checked = true then subfolders := true;              //include subfolders
 if  checkbox3.Checked = false then exclude := faDirectory;
 sl := TStringList.Create;
  begin
    try
      FindFiles(rootfolder, include, exclude, subfolders, sl);
      Listbox1.Items.AddStrings(sl);
    finally
      sl.Free;
    end;
   end;
end;

procedure Trenamer_form.Button2Click(Sender: TObject);  // add just selected items to other ListBox
var
counter: integer;
begin
  counter := 0;
  while counter < (Listbox1.Count) do
  begin
  if listbox1.Selected[counter] then
    begin
    Listbox2.Items.Add(Listbox1.Items.Strings[counter]);
    end;
  counter := counter +1;
  end;
  Listbox2.Refresh;
end;

procedure Trenamer_form.Button4Click(Sender: TObject); //name to uppercase
var
counter: integer;
begin
  counter := 0;
  while counter < (Listbox2.Items.Count) do
  begin
      RenameFile(Listbox1.Items.Strings[counter],(AnsiUpperCaseFileName(Listbox2.Items.Strings[counter])));
      RenameDir(Listbox1.Items.Strings[counter],(AnsiUpperCaseFileName(Listbox2.Items.Strings[counter])));
  counter := counter +1;
  end;
end;


Last one is same for lowercase conversion, just use AnsiLowerCase()
Just one remark, if folder is open in other application, it won't be renamed. I think that there is the same situation for files.

Regards
Spasic Boban aka bobby100

Moderiert von user profile iconMotzi: Code- durch Delphi-Tags ersetzt.
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Sa 22.05.04 09:15 
cool.
have fun with delphi and just come back to the DF if you have questions !

_________________
In the beginning was the word.
And the word was content-type: text/plain.
bobby Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 25

Win XP
D7 Prof
BeitragVerfasst: Di 01.06.04 14:00 
Program finished, if you have time, take a look :
members.chello.at/bobby100/
Section PROGRAMS, sub-section The GUI .
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Di 01.06.04 15:59 
nice tool !

_________________
In the beginning was the word.
And the word was content-type: text/plain.