Ecere SDK/eC Forums • View topic - Code Snippets 2:List Files In Dir




Ecere SDK/eC Forums

Ecere Developers Community

Code Snippets 2:List Files In Dir

来自中国的朋友,欢迎您在本版面使用中文讨论问题。请注意,如果您想得到不懂中文的人的帮助,请同时提供英文译文。
Help and discussions in Chinese.

Code Snippets 2:List Files In Dir

Postby samsam598 » Mon Aug 22, 2011 4:08 am

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 {};
 
 
Last edited by samsam598 on Fri Sep 16, 2011 1:59 am, edited 2 times in total.
samsam598
 
Posts: 208
Joined: Thu Apr 14, 2011 9:44 pm

Re: Code Snippets 2:List Files In Dir

Postby liqi98136 » Wed Aug 24, 2011 7:43 am

顶一个,加油.
liqi98136
 
Posts: 53
Joined: Sun Jan 17, 2010 11:37 pm


Return to 欢迎使用中文讨论

Who is online

Users browsing this forum: No registered users and 7 guests

cron