• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 353
  • Last Modified:

Directory traversal directory+file character limit

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
billy_98_1
Asked:
billy_98_1
  • 2
  • 2
  • 2
  • +2
1 Solution
 
gregoryyoungCommented:
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
 
billy_98_1Author Commented:
There aren't any clever work arounds?
0
 
Bob LearnedCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
gregoryyoungCommented:
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
 
billy_98_1Author Commented:
I used the shortpath property, using the file system object. It took a lot longer, but it bought me enough extra path space.
0
 
wayko621Commented:
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
 
Bob LearnedCommented:
?
0
 
Computer101Commented:
PAQed - no points refunded (of 250)

Computer101
E-E Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now