Solved

Directory traversal directory+file character limit

Posted on 2004-08-11
10
324 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

947 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

20 Experts available now in Live!

Get 1:1 Help Now