Ecere SDK/eC Forums
http://ec-lang.org/community/
Print view

Code Snippets 2:List Files In Dir
http://ec-lang.org/community/viewtopic.php?f=30&t=159
Page 1 of 1
Author:  samsam598 [ Mon Aug 22, 2011 4:08 am ]
Post subject:  Code Snippets 2:List Files In Dir

Purpose:Basic usage of FileListing class and SavingDataBox-DirPath,select a folder ,iterate through it and list all files under it and its sub folders,fill full pathname of them into the editBox.

Code: Select all

 
import "ecere" 
class Form1 : Window
{
   text = "Form1";
   background = activeBorder;
   borderStyle = sizable;
   hasMaximize = true;
   hasMinimize = true;
   hasClose = true;
   tabCycle = true;
   size = { 576, 432 };
   nativeDecorations = true;
 
   String s;
   s = (s = new char[MAX_LOCATION], GetWorkingDir(s, MAX_LOCATION), s);
 
   SavingDataBox pathBox   
   {
      this, size = { 301, 20 }, anchor = { left = 176, top = 24, right = 91 }, data = &s; type = class(DirPath);;
   };
   Label label1 { this, text = "(D)请输入或选择文件路径:", altD, size = { 140, 13 }, position = { 24, 24 }, labeledWindow = pathBox };
   Button btnView 
   {
      this, text = "(V)iew", altV, minClientSize = { 55, 21 }, isDefault = true, size = { 55, 21 }, anchor = { top = 24, right = 25 };
 
      bool NotifyClicked(Button button, int x, int y, Modifiers mods)
      {
         this.txtFiles.Clear();
 
         listDir(s);
         return true;
      }
   };
   EditBox txtFiles { this, text = "editBox1", anchor = { left = 16, top = 64, right = 18, bottom = 17 }, hasHorzScroll = true, hasVertScroll=true, fullRender = true, readOnly = true, multiLine=true };
 
   void listDir(char* path)
   {
      FileListing listing {path};
      while(listing.Find())
      {
         if(listing.stats.attribs.isDirectory)
         {
            listDir(listing.path) ;
         }
         else
         {
            this.txtFiles.AddS(listing.path);
            this.txtFiles.AddS("\n");
 
         }
      }
      this.txtFiles.SetViewToCursor(true);
   }
 
   bool OnPostCreate(void)
   {
      pathBox.Activate();
      return true;
   }
 
   ~Form1()
   {
      delete s;
   }
}
 
Form1 form1 {};
 
 
Author:  liqi98136 [ Wed Aug 24, 2011 7:43 am ]
Post subject:  Re: Code Snippets 2:List Files In Dir

顶一个,加油.
All times are UTC-05:00 Page 1 of 1