All source code in ASP/ VbScript Ask a ASP/ VbScript Pro Discussion Forum Categories All jobs in ASP/ VbScript
Quick Search for:  in language:    
recurse,walkthrough,every,subdirectory,given,
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 281,486. lines
 Jobs: 101. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login

NEW! LEARNING CENTER
Special educational offers, white papers, webcasts, podcasts

  NEW! Download Rational Performance Tester V8 (download now)
  NEW! Download Rational Functional Tester V8 (download now)
  NEW! Download Rational Service Tester for SOA Quality V8 (download now)
  NEW! Teleconference: Quality In Action - Using Rational Quality Manager with Functional, Performance and Web Service Testing Products (download now)
  NEW! Introducing IBM Rational AppScan Developer Edition – easing security testing by non-security professionals (download now)

 

 


Latest postings for ASP/ VbScript.
Click here to see a screenshot of this code!Mess Officer Management System (Sistem Pengurusan Mess Pegawai)
By Mohd Fauzi on 11/23

(Screen Shot)

Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!



 
 
   

ASP Procedure Used To Recurse Through All SubFolders Of Any Given Path

Print
Email
 
VB icon
Submitted on: 8/14/2000 10:38:38 PM
By: ObjectMethod 
Level: Intermediate
User Rating: By 7 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 21941 times.
 
(About the author)
 
     Use it to recurse (walk-through) every sub-directory of any given path. Use it to find a file or list all files in any given path.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: ASP Procedure Used To Recurse Th
    '     rough All SubFolders Of Any Given Path
    ' Description:Use it to recurse (walk-th
    '     rough) every sub-directory of any given 
    '     path. Use it to find a file or list all 
    '     files in any given path.
    ' By: ObjectMethod
    '
    ' Inputs:"PATH" = Starting location of s
    '     earch
    '
    ' Returns:You can write your own code fo
    '     r each file or folder found.
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/vb/scripts/Sho
    '     wCode.asp?txtCodeId=6309&lngWId=4    'for details.    '**************************************
    
    <%
    	Sub Recurse(Path)
    		
    		Dim fso, Root, WindowsFolder, Files, _
    			Folders, File, i, FoldersArray(100)
    			
    		Set fso = Server.CreateObject("Scripting.FileSystemObject")
    		Set Root = fso.getfolder(Path)
    		Set Files = Root.Files
    		Set Folders = Root.SubFolders
    		For Each File In Files
    			'''''''''''''''''''''''''''''
    			'Code For Each File Found
    			'Goes Here!
    			'''''''''''''''''''''''''''''
    		Next
    			
    		For Each Folder In Folders
    			'''''''''''''''''''''''''''''
    			'Code For Each Folder Found
    			'Goes Here!
    			'''''''''''''''''''''''''''''
    			FoldersArray(i) = Folder.Path
    			i = i + 1
    		Next
    			 	
    		For i = 0 To UBound(FoldersArray)
    			if FoldersArray(i) <> "" Then 
    				Recurse FoldersArray(i)				
    			Else
    				Exit For
    			End if
    		Next
    		
    	End Sub
    %>

 
 Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
8/14/2000 10:46:15 PMSweet Deluxe (Author)

Questions, comments, etc . . .
(If this comment was disrespectful, please report it.)

 
8/22/2000 7:49:58 PMTim Fischer

Easy to understand and use. Keep codin.
(If this comment was disrespectful, please report it.)

 
9/26/2000 10:01:14 AMStephane PIAZZA

I've used your script to create mine. Thanks a lot. U can have a look by searching the "Tree Menu Based on Directories" and also the Thumbnail one.
Tanks again .....
I'll mentionned u on the programm description.
I've rated your code.

(If this comment was disrespectful, please report it.)

 
12/12/2000 11:40:35 PMSweetDeluxe (Author)

I've just realized one more thing .. you should also Dim the variable 'Folder'
Just add it to the list of variables being declared in the beginning of the procedure.
(If this comment was disrespectful, please report it.)

 
12/13/2000 1:35:21 PMSteven

I get this error:

Server object error 'ASP 0177 : 800a004c'
Server.CreateObject Failed
/asp/menu.asp, line 102
The operation completed successfully.

Is this due to permissions I have set up on my server?

(If this comment was disrespectful, please report it.)

 
3/2/2001 10:30:07 AMVincent

You saved my butt today... thanks A LOT!!
(If this comment was disrespectful, please report it.)

 
7/6/2001 12:57:42 PMPatrick

Nice code, works very well.
(If this comment was disrespectful, please report it.)

 
7/31/2001 2:24:30 PMAlastair

You can actually shorten the code and the declarations if you simply use a folder object as the recursive parameter instead of the path info. that way you do not need to build the path array each time you recurse.

Sub recurse( pobjFolder )
Dim strTemp ' Temp that holds the selected file name
Dim objItem ' Loop var

'**** Recursively loop through each sub-folder
For Each objItem In pobjFolder.SubFolders
recurse( objItem )
Next 'objItem

'**** Loop through each item (file) in the current folder
For Each objItem In pobjFolder.Files
'CODE GOES HERE FOR EACH FILE
Next 'objItem

'**** Clean-up
Set strTemp = Nothing
Set objItem = Nothing
Set pobjFolder = Nothing
End Sub
(If this comment was disrespectful, please report it.)

 
7/31/2001 2:27:54 PMAlastair

Sorry for the messy code, it was transformed improperly on submission. Anyways, this sub uses two variables and one parameter instead of the above 8 with a 100 element array. All you need to do is pass in a pointer to the starting foler. Enjoy!
(If this comment was disrespectful, please report it.)

 
12/5/2001 9:19:46 PMjosiane

sorry , i'm not sure what to do in this, by the way, i am just a beginner, i hope anyone here could help me in this program. Thanks a million.
(If this comment was disrespectful, please report it.)

 
2/4/2004 1:09:30 AM

hi,
when i run this file the screen is blank,where i have to make changes?
please help me out."pinki_jinu@yahoo.com"
(If this comment was disrespectful, please report it.)

 
1/4/2008 1:05:01 AM

good
(If this comment was disrespectful, please report it.)

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author from the email account you registered on the site, so you can correspond directly.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
To post feedback, first please login.


 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | Open Letter from Moderators | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997-2008 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.   Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.