
Two short VBA programs to list folders and files and store results in an array
- or -
Post a project like this3749
$$
- Posted:
- Proposals: 3
- Remote
- #690004
- Awarded
Description
Experience Level: Intermediate
General information for the business: Two rutines to list the files in a folder and the fles in any of its sub-folders
Kind of development: New program from scratch
Num. of modules: 2 progams
Description of every module: This should consist of two VBA programs running in Excel V10:
Findiles & getfoldercontents (this may be called recursively every time a folder is encountered)
Option explicit
Public sub findfiles(byval strpath as string)
Dim stritems(1000)as string, intlevel as integer, intcount as integer
getfoldercontents strpath, stritems(), intlevel, intcount
End sub
findfolders just calls getfoldercontents and provides the arrays in which the results of calling getfoldercontents are to be saved.
Strpath is the opening path (e.g: c:\test).
On each call to getfoldercontents, it should increase the value of intcount by 1 and add the name of the folder now being searched to stritems(intcount) which should be set:
stritems(intcount)=string(intlevel,chr(9))+
Then intlevel is increment by 1 and all the files in the folder are added to stritems and intcount incremented by 1 for each file name added:
stritems(intcount) = string(intlevel,chr(9))+
Just prior to each exit from getfoldercontents, intlevel is reduced by 1.
Description of requirements/functionality: Outputs a string array listing all the folders and files in the initial root folder. The intlevel parameter sets thr enumber of chr(9) tabs
OS requirements: Windows
Extra notes:
Kind of development: New program from scratch
Num. of modules: 2 progams
Description of every module: This should consist of two VBA programs running in Excel V10:
Findiles & getfoldercontents (this may be called recursively every time a folder is encountered)
Option explicit
Public sub findfiles(byval strpath as string)
Dim stritems(1000)as string, intlevel as integer, intcount as integer
getfoldercontents strpath, stritems(), intlevel, intcount
End sub
findfolders just calls getfoldercontents and provides the arrays in which the results of calling getfoldercontents are to be saved.
Strpath is the opening path (e.g: c:\test).
On each call to getfoldercontents, it should increase the value of intcount by 1 and add the name of the folder now being searched to stritems(intcount) which should be set:
stritems(intcount)=string(intlevel,chr(9))+
Then intlevel is increment by 1 and all the files in the folder are added to stritems and intcount incremented by 1 for each file name added:
stritems(intcount) = string(intlevel,chr(9))+
Just prior to each exit from getfoldercontents, intlevel is reduced by 1.
Description of requirements/functionality: Outputs a string array listing all the folders and files in the initial root folder. The intlevel parameter sets thr enumber of chr(9) tabs
OS requirements: Windows
Extra notes:

Geoffrey R.
98% (48)Projects Completed
59
Freelancers worked with
44
Projects awarded
65%
Last project
4 May 2020
United Kingdom
New Proposal
Login to your account and send a proposal now to get this project.
Log inClarification Board Ask a Question
-
There are no clarification messages.
We collect cookies to enable the proper functioning and security of our website, and to enhance your experience. By clicking on 'Accept All Cookies', you consent to the use of these cookies. You can change your 'Cookies Settings' at any time. For more information, please read ourCookie Policy
Cookie Settings
Accept All Cookies