CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > starter_kits_and_source_projects.internet_explorer_web_controls Tags:
Item Type: NewsGroup Date Entered: 4/28/2004 8:41:19 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 0 Views: 26 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
2 Items, 1 Pages 1 |< << Go >> >|
ZachyG
Asp.Net User
Scan a Folder4/28/2004 8:41:19 PM

0/0

I wrote some code to recursivly scan a folder and add all the files and folder to a tree. just thought i would share if anyone wants to use it.

If it helps you out Great!, if not sorry to bother.


///////////////////////////
'the main tree node
Dim oNewTreeNode As New TreeNode

LoopDir("C:\temp\", oNewTreeNode)
///////////////////////////


Private oDir As System.IO.Directory

Private Sub LoopDir(ByVal DirPath As String, ByRef OldNode As TreeNode)
Dim sDirNames() As String 'the names of the new directories
Dim oNewNode As New TreeNode 'the new tree node to be added

'get the directories
sDirNames = oDir.GetDirectories(DirPath)

'loop through all the directories found
For i As Integer = 0 To sDirNames.Length - 1 Step 1

'make a new node for the new folder found
oNewNode = New TreeNode

'set the text to the folder name
oNewNode.Text = GetFolderName(sDirNames(i))
'set the image to a folder
oNewNode.ImageUrl = AppSettings("ImageDir") & "folder.gif"
'add the new node to the old node
OldNode.Nodes.Add(oNewNode)

'loop through the directories for new directories
LoopDir(sDirNames(i), oNewNode)
Next

'now that we have the directories; get the files in the directory
getDirFiles(DirPath, OldNode)

End Sub

Private Sub getDirFiles(ByVal dirName As String, ByVal Node As TreeNode)
Dim sFileNames() As String 'the names of all the files in the directory
Dim sFileNameExt As String 'the name of the file with the extection
Dim sFileNameNoExt As String 'the name of the file with out the extection
Dim sFileNameParts() As String 'the file name and ext
Dim sExt As String 'the extion of the file
Dim sFilePath As String 'the name of the file path
Dim sFilePaths() As String 'the name of all the part of the file path
Dim sFilePathFileSplits() As String 'the file path split at the file dir
Dim sFilePathFileSplit As String 'the part after the split
Dim oNewNode As New TreeNode 'the new tree node to be added

'get all the files in the directory
sFileNames = oDir.GetFiles(dirName)

'loop through all the files
For i As Integer = 0 To sFileNames.Length - 1 Step 1

'make the new node
oNewNode = New TreeNode

'this get the information about the file
sFilePath = sFileNames(i)
sFilePaths = Split(sFilePath, "\", , CompareMethod.Text)
sFilePathFileSplits = Split(sFilePath, "Files", , CompareMethod.Text)
sFilePathFileSplit = sFilePathFileSplits(sFilePathFileSplits.Length - 1)
sFileNameExt = sFilePaths(sFilePaths.Length - 1)
sFileNameParts = Split(sFileNameExt, ".", , CompareMethod.Text)
sFileNameNoExt = sFileNameParts(0)
sExt = sFileNameParts(1)

'set the new nodes properities
oNewNode.Text = sFileNameNoExt
oNewNode.Target = "oFrame"

'fomrat the string properly
sFilePathFileSplit = FormatPath(sFilePathFileSplit)

'add the file path
oNewNode.NavigateUrl = AppSettings("FileDirLocation") & sFilePathFileSplit

'depending on the Ext we want to use a special icon
Select Case sExt.ToLower()
Case "pdf"
oNewNode.ImageUrl = AppSettings("ImageDir") + "pdf.jpg"
Case "xls"
oNewNode.ImageUrl = AppSettings("ImageDir") + "excel.jpg"
Case "doc"
oNewNode.ImageUrl = AppSettings("ImageDir") + "word.jpg"
Case "ppt"
oNewNode.ImageUrl = AppSettings("ImageDir") + "powerpoint.jpg"
Case "txt"
oNewNode.ImageUrl = AppSettings("ImageDir") + "text.jpg"
Case "zip"
oNewNode.ImageUrl = AppSettings("ImageDir") + "zip.jpg"
Case Else
oNewNode.ImageUrl = AppSettings("ImageDir") + "other.jpg"
End Select


'add the new node
Node.Nodes.Add(oNewNode)
Next
End Sub

Private Function GetFolderName(ByVal FolderString As String) As String

'split out the name by folder divider
Dim sCrumbs() As String = Split(FolderString, "\", , CompareMethod.Text)

'return the last section
Return sCrumbs(sCrumbs.Length - 1)
End Function


Private Function FormatPath(ByVal Path As String) As String
'remove the first slash character
Path = Path.Remove(0, 1)

'return the string with the slashes corrected
Return Path.Replace("\", "/")
End Function
RemarkLima
Asp.Net User
Re: Scan a Folder6/20/2006 4:39:55 PM

0/0

That's excellent! Many thanks for sharing, it works a treat.

I've just added a condition to name the root of the Nodes if it's empty but otherwise absolutely spot on!

Mark


"Yes, it's a perfect scale model of the universe's largest bottle. I put a tiny spaceship inside to keep it from being boring."
2 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Google Search And Tools in a Snap: In a Snap Authors: Preston Gralla, Pages: 353, Published: 2006
Mastering Visual Basic.NET Authors: Evangelos Petroutsos, Pages: 1153, Published: 2002
Networks in a Flash: Making Broadband Work for You Authors: Hrair Aldermeshian, Thomas B. London, Pages: 328, Published: 2003
Mastering Microsoft Visual Basic 2008 Authors: Evangelos Petroutsos, Mark Ridgeway, Pages: 1118, Published: 2008
Microsoft Windows XP Networking Inside Out: Complete Edition. Authors: Curt Simmons, James Causey, Pages: 677, Published: 2002
Alan Simpson's Windows XP Bible Authors: Alan Simpson, Pages: 720, Published: 2004
The Unauthorized Guide to Windows 98 Authors: Paul McFedries, Pages: 784, Published: 1999
Alan Simpson's Windows Vista Bible: Desktop Edition Authors: Alan Simpson, Bradley L. Jones, Pages: 860, Published: 2007
Windows Vista Timesaving Techniques for Dummies Authors: Woody Leonhard, Pages: 560, Published: 2007
My New Mac: 52 Simple Projects to Get You Started Authors: Wallace Wang, Pages: 451, Published: 2008

Web:
Scan To Folder Report as spam Question - Post 1 of 3; Scan To Folder: I am tring to setup a scan to folder option on a Multi-function Printer that I have. ...
Scan to Folder Scan files can be sent to the shared folders of Windows. At the end of the following steps your scanned document will be placed on the shared folder ...
Scan to folder on networked server - Tech Support Forum Does anyone know on Server 2003 what a multifunction printer would be considered to allow the scan to folder option?
Savin scan to folder - Copytechnet.com I have a client that has a Savin 8025ep with scan and fax. They are trying to scan to folder by searching their server through the scanner ...
Business support forums - Scan-to-folder failure - unable to reach ... This is the first step I perform to diagnose a scan to folder issue and 99% of the time the scan works. Your right though there does seem to ...
Toshiba copier file path for scan to folder - NOVELL FORUMS We got a new copier that does a bunch of stuff. Instead of using the smb share on the copier, I want the scan jobs to go to a folder on a NW ...
Scan web Folder for Viruses - Access World Forums Scan web Folder for Viruses Web Design and Development.
Need help configuring scan-to-folder on a Ricoh Aficio 1232c ... I just can't seem to find information on configuring a Ricoh 1232c multifunction device to scan to folders. I can't locate the manuals and ...
How to scan a folder in Java? - Stack Overflow How to scan a folder in Java? vote up 2 vote down star. How can I get a tree of all the files from a current folder in Java? java files folders ...
Idle scan - exclude folder? - Norton Internet Security / Norton ... When I setup a custom scan of the partition, g:, and then excluded the folder g: \thefolder, the custom scan-window did NOT scan that folder. ...

Videos:
IP-FAX Scan to Folder カラースキャナで読み込んだ画像データーをパソコンの任意のフォルダーに取り込むことができます。
eCopy Embedded on Ricoh Video clip of eCopy Embedded running natively on a Ricoh MFD and showing scan-to-email and scan-to-folder
Ricoh GlobalScan Video clip of GlobalScan V2 running natively on a Ricoh MFD showing scan-to-mail and scan-to-folder
Scan folder site and hacking them.. this video show you how scan site folder and you see will all file site your target n search hole site.
Scan folder site and hacking them part 2 this video show you how scan site folder and you see will all file site your target n search hole site.
Win32 Netsky AntiVirus Removal Once you have completed all of this then your computer system should be free of the Netsky virus, but in order to make sure you will want to run a ...
iCat Vision Tutorial This is a step by step video of how to utilize the application that comes on each CD that the dentist will receive after their patient has ...
Iphone finger scan first of all you should download finger scan apps on your iphone and follow above steps: 1.download finger scan application from http://www ...
DL TV Episode 76 * Welllllll… maybe not nuked, but he had a Trojan try to sneak a keylogger onto his system… * Trend Micro’s free online virus scan sorted him ...
eCopy ShareScan ScanStation on Ricoh Video clip of eCopy ScanStation running natively on a Ricoh MFD showing scan to secure email and scan to EDM




Search This Site:










ibs like the old bbs's?

how do i clear the recent projects list in vs.net 2005?

dnn2.0.4:: questions about vendors and banners (part two)

formatting date in vwd

using vs.net to copy dnn to commercial host?

visual studio 2005 web deployment project especial characters

logging in from multiple pages

installing survey and user online modules

please help..

.text

validation with a tree view/form view

opening up new possibilities for inter-module processes

button.usesubmitbehavior=false comments

convert classifieds starter kit to work with ms access

minrequiredpasswordlength not recognised with mysql as database

preview button

checking for null

module alignment

localization issues stumped

get request user windows account

how to use active directory (ad) for authentication

are there any exams for asp.net ?

forms based authentication not.. authenticating!

skin making tutorial

can container sizes be controled in dotnetnuke 3.0.13?

remoting client activated

drag and drop controls to asp:table designer mode not working

menu

passing linefeeds in string variable generating javascript

"cell" link ie wierdness in menu list <li> with class aspnet-menu-leaf

 
All Times Are GMT