List subfolders and files in a specified folder

Source: Internet
Author: User

VBA lists all subfolders in the folder

 

Sub showfolderlist () <br/> dim FSO as object, ofolder as object <br/> dim ofolderarray as object, f As object <br/> dim K & </P> <p> set FSO = Createobject ("scripting. fileSystemObject ") <br/> set ofolder = FSO. getfolder ("C:/Program Files") <br/> set ofolderarray = ofolder. subfolders <br/> for each F in ofolderarray <br/> K = k + 1 <br/> cells (k, 1) = F. name <br/> next </P> <p> end sub

 

 

VBA list all files in the folder

 

Sub mydir () <br/> dim mydir as string <br/> dim I & <br/> range ("A: "). clearcontents <br/> mydir = Dir (thisworkbook. path &"/*. * ", vbnormal) <br/> do while mydir <>" "<br/> I = I + 1 <br/> cells (I, 2) = mydir <br/> mydir = dir <br/> loop <br/> end sub

 

 

Vsto lists all subfolders and files in a folder (C #)

 

Int I = 0, K = 0; <br/> directoryinfo dir = new directoryinfo (@ "C:/Windows"); <br/> directoryinfo [] dirs = dir. getdirectories (); <br/> foreach (directoryinfo folder in dirs) <br/>{< br/> I ++; <br/> This. range ["A" + I, missing]. value2 = folder. name; <br/>}< br/> fileinfo [] files = dir. getfiles (); <br/> foreach (fileinfo file in files) <br/>{< br/> K ++; <br/> This. range ["B" + k, missing]. value2 = file. name; <br/>}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.