[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Directory traversal directory+file character limit

Posted on 2004-08-11
10
Medium Priority
?
349 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

649 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