[SOLVED] DirectoryEdit1 component Refresh/Update question lazarus / 31-LCL ---------------------------------------------------------------------- bzman24 · 2014-07-12 02:35 Hello, Here is what I am using: Lazarus version: 1.2.4 Lazarus svn revision: 45510 Lazarus build date: 2014/06/14 Lazarus was compiled for i386-win32 Lazarus was compiled with fpc 2.6.4 Running on a Win7 desktop, 3 Gig of memory. ============================= Below is the code I am using to populate the check list box.  Initially when I start the program the check list box is populated with the files as found in the folder the program resides in.  This is what I want.  I then can click the check box of the files I want and execute more code to change the file names of just those files whose check box was checked.  This all works fine but my problem is, is there then a way to do an update or refresh to have the check list box then show the files with the new file names?  I can't find any documentation on doing this.  I did find that the DirectoryEdit1 has a Refresh and an Update procedure tied to them, but I can't get them to do anything.  When I try either of them in a new event as also shown below, nothing happens.  I'm doing something wrong, but I'm not sure what.  Any ideas or documentation on this?  My workaround now is to change folders in the directory edit box and then go back to the original folder, while running the program.  It then updates everything to show the changes, but I would like a better way if possible. Thanks, bzman ======================= PROCEDURE TForm1.DirectoryEdit1Change(Sender: TObject); BEGIN   FileListBox1.Clear;   CheckListBox1.Clear;   FileListBox1.Directory := DirectoryEdit1.Directory;   CheckListBox1.Items.AddStrings(FileListBox1.Items);   Label_ItemCountNumber.Caption := IntToStr(CheckListBox1.Items.Count); end; PROCEDURE TForm1.Button_RefreshClick(Sender: TObject); BEGIN   FileListBox1.Clear;   CheckListBox1.Clear;   {DirectoryEdit1.Update;} {using either one here}   DirectoryEdit1.Refresh;   FileListBox1.Directory := DirectoryEdit1.Directory;   CheckListBox1.Items.AddStrings(FileListBox1.Items);   Label_ItemCountNumber.Caption := IntToStr(CheckListBox1.Items.Count); end; ---------------------------------------------------------------------- Roland57 · 2014-07-12 07:30 Hello! Here is a simple code that seems to do what you want (if I correctly understand it). Code: [Select]procedure GetFiles(p: string; a: longint; s: TStrings); var   r: TSearchRec; begin   s.Clear;   if FindFirst(p, a, r) = 0 then   repeat     s.Add(r.Name);   until FindNext(r) <> 0;   FindClose(r); end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin   GetFiles(     ExtractFilePath(ParamStr(0)) + '*.*',     faArchive,     CheckListBox1.Items   ); end; procedure TForm1.Button2Click(Sender: TObject); var   i: integer; begin   with CheckListBox1 do     for i := 0 to Items.Count - 1 do       if Checked[i] then         RenameFile(           Items[i],           '_' + Items[i]         );   Button1Click(nil); end; ---------------------------------------------------------------------- bzman24 · 2014-07-13 01:19 Roland, Let me try your code and see if it does what I need. Thanks, bzman ---------------------------------------------------------------------- bzman24 · 2014-07-13 03:39 Roland, Thanks for the code example and it does do exactly as I want, however it seems to only work on the files that are in the same folder as the program is.  If I have 20 different folders that have files to be processed then I would need 20 copies of the program (1 in each folder).  This would work, but I would like to be able to change the working folder location within the program.  That is the purpose of using the DirectoryEdit component. After trying various things to get it to work as needed, the change as shown below seems to give me some hope this might be the answer, but the results of testing gives me weird results.  I'm wondering if this is because of the TSearchRec limits as talked about in my TP6 books?  When I run this new line, it shows the results in the CheckListBox that are the files in the previous folder and not the folder I am in. 2 examples: 1 - If I am in 'C:\Users\BZMan\Music\ADO' folder, executing your code with the change shown below, gives me the files listed in 'C:\Users\BZMan\Music' folder and not the files listed in 'C:\Users\BZMan\Music\ADO' folder like the DirectoryEdit component gives me. 2 - If I am in 'C:\Music Files' folder, executing your code with the change shown below, gives me the files listed in 'C:\' folder and not the files listed in 'C:\Music Files' folder like the DirectoryEdit component gives me. These are both the results with the executable program residing in its original folder of: 'C:\Projects\Filename Change'. ================== Your original line: GetFiles(     ExtractFilePath(ParamStr(0)) + '*.*',     faArchive,     CheckListBox1.Items   ); My new line: GetFiles(     ExtractFilePath(DirectoryEdit1.Directory) + '*.*',     faArchive,     CheckListBox1.Items   ); Thanks again for your code and thoughts on this.  I still think there must be a way using just the DirectoryEdit component. bzman ---------------------------------------------------------------------- Roland57 · 2014-07-13 06:52 The result that you get is logical. Code: [Select]ShowMessage(ParamStr(0)); ShowMessage(ExtractFilePath(ParamStr(0))); ShowMessage(ExtractFilePath('C:\Users\BZMan\Music')); So the following modification should solve your problem. Code: [Select]GetFiles(DirectoryEdit1.Directory + '\*.*', ---------------------------------------------------------------------- bzman24 · 2014-07-14 01:31 Roland, You are absolutely correct.  That last code snippet does exactly what I want to do.  Thank You!  Thank You!  Thank You!  Looking at what code was needed to do what I was trying to do is a lot simpler and straight forward than what I was thinking.  I was way over thinking this whole thing. Thanks to you and this forum, this is now resolved. bzman