Solved

Directory traversal directory+file character limit

Posted on 2004-08-11
10
330 Views
Last Modified: 2008-03-03
Hi,
I'm working on a project to traverse directories over a network, making statistics on what files exist.
While mostly windows computers, there are also sun boxes which I can access as if they were windows shares.
The problem is I cant find a way to reference files and folders that are above 240-260(?) characters in their path name down a directory tree. Doing c:\ would get all the files on my hard-disk, but doing \\pc556679393\c$\ would limit me to ones that are less than the boundary.
I access the folder I would like to traverse, recursing down, using it's computer name and drive letter, and possibly some folders eg pc5566890\e$\userdata\ etc (missing the e$ for the sun box). But, these initial paths can be quite long, and without mounting them as a drive letter, which I'm reluctant to do, I can't think of a way to make them shorter.

I have been using:
                    For Each CurrentFile In Directory.GetFiles(CurrentDir)
                        CurrentFileInfo = New FileInfo(CurrentFile)
                        'Do something
                    Next

Then I tried using the file system object, but that also didn't work. I tried using the shortpath property of the objects, but that didn't buy me anything. :(

Any ideas?
Performance is desired, as doing all the files and folders will take some time, but it having a working version is more important!
0
Comment
Question by:billy_98_1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 11775151
that is a limitation of the file object...

"on Windows-based platforms, paths must be less than 248 characters, and file names must be less than 260 characters."
0
 
LVL 1

Author Comment

by:billy_98_1
ID: 11776410
There aren't any clever work arounds?
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12108007
http://www.osronline.com/lists_archive/ntfsd/thread194.html

NT unicode APIs can accept 32k-char paths if they follow a certain
format (have \\?\ as a prefix).  This "tells the function to turn off
path parsing,"
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12108060
yeah but those paths also cause problems (even with things such as explorer). It is generally better to work around the issue if at all humanly possible.
0
 
LVL 1

Author Comment

by:billy_98_1
ID: 12110369
I used the shortpath property, using the file system object. It took a lot longer, but it bought me enough extra path space.
0
 

Expert Comment

by:wayko621
ID: 12201246
this is for local all u have to add is network computer in oNode.text to be \\computername\c$\programfiles
it can be called using the active directory
onode.text = "\\" + Mid(CStr(computername.GetDirectoryEntry.Name), 4) + \c$\programfiles"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oNode As New System.Windows.Forms.TreeNode()
        Try
            oNode.ImageIndex = 0    ' Closed folder
            oNode.SelectedImageIndex = 0
            oNode.Text = "c:"
            TreeView1.Nodes.Add(oNode)
            oNode.Nodes.Add("")
        Catch ex As Exception
            MsgBox("Cannot create initial node:" & ex.ToString)
            End
        End Try
    End Sub
    Private Sub TreeView1_BeforeExpand(ByVal sender As Object, ByVal e As _
            System.Windows.Forms.TreeViewCancelEventArgs) Handles _
            TreeView1.BeforeExpand

        If e.Node.ImageIndex = 2 Then Exit Sub

        Try
            If e.Node.GetNodeCount(False) = 1 And e.Node.Nodes(0).Text = "" Then
                e.Node.Nodes(0).Remove()
                EnumerateChildren(e.Node)
            End If
        Catch ex As Exception
            MsgBox("Unable to expand " & e.Node.FullPath & ":" & ex.ToString)
        End Try

        If e.Node.GetNodeCount(False) > 0 Then
            e.Node.ImageIndex = 1
            e.Node.SelectedImageIndex = 1
        End If

    End Sub

    Private Sub EnumerateChildren(ByVal oParent As System.Windows.Forms.TreeNode)

        Dim oFS As New DirectoryInfo(oParent.FullPath & "\")
        Dim oDir As DirectoryInfo
        Dim oFile As FileInfo

        Try
            For Each oDir In oFS.GetDirectories()
                Dim oNode As New System.Windows.Forms.TreeNode()
                oNode.Text = oDir.Name
                oNode.ImageIndex = 0
                oNode.SelectedImageIndex = 0
                oParent.Nodes.Add(oNode)
                oNode.Nodes.Add("")
            Next
        Catch ex As Exception
            MsgBox("Cannot list folders of " & oParent.FullPath & ":" & ex.ToString)
        End Try

        Try
            For Each oFile In oFS.GetFiles()
                Dim oNode As New System.Windows.Forms.TreeNode()
                oNode.Text = oFile.Name & " (" & oFile.Length & " bytes)"
                oNode.ImageIndex = 2
                oNode.SelectedImageIndex = 2
                oParent.Nodes.Add(oNode)
            Next
        Catch ex As Exception
            MsgBox("Cannot list files in " & oParent.FullPath & ":" & ex.ToString)
        End Try

    End Sub
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12201260
?
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 12376737
PAQed - no points refunded (of 250)

Computer101
E-E Admin
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - SQL Timeout 9 51
VB.net Progress Bar - Maximum Value too large 2 26
VB.Net creating Contact in Outlook 1 60
vb.net datagrid point 4 23
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question