Solved

Directory traversal directory+file character limit

Posted on 2004-08-11
10
322 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
  • 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now