Announcement

Collapse
No announcement yet.

Full path length

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Full path length

    I need to copy user files from a Novell volume to an NTFS share residing on an 2003 R2 server. The copy is done from the user's computer, XP SP2. During the process, I encountered errors with some links in Favorites, that the full path is longer than 260 characters.
    Is there any way I can find those files (any script to run ) prior the copy process, so I'll be able to deal with them?
    TIA.

    Sorin Solomon


    In order to succeed, your desire for success should be greater than your fear of failure.
    -

  • #2
    Re: Full path length

    here is a sample:
    Code:
    'Treshholds
    Const maxPathLength   = 259
    Const maxFolderDepth  = 8
    Const maxFolderLength = 128
    Const maxFileLength   = 240
    
    rootDir = "i:"
    logFile = "c:\scripts\filesys.log"  'folder must exists
    
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    On Error resume Next
    Set objLogFile = objFSO.CreateTextFile(logFile, 2, True)
    If err.number <> 0 then
      wsh.echo "logfile is in use, the script stopped"
      wsh.quit
    End If
    On Error GoTo 0
    
    dim fleCnt : fleCnt = 0
    dim flrCnt : flrCnt = 0
    dim errCnt : errCnt = 0 
    
    Set objFolder = objFSO.GetFolder(rootDir)
    
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
      call ForEachFile(objFile)
    Next
    
    ShowSubfolders objFolder
    
    objLogFile.Writeline
    objLogFile.Write "done," _
                  & vbCrLf & "- found files"   & vbTab & fleCnt _
                  & vbCrLf & "- found folders" & vbTab & flrCnt _
                  & vbCrLf & "- access errors" & vbTab & errCnt
    objLogFile.Close
    
    
    wsh.echo "done, " & rootDir, " and subfolders" _
                      & vbNewLine & "- found files" & vbTab, fleCnt _
                      & vbNewLine & "- found folders" & vbTab, flrCnt _
                      & vbNewLine & "- access errors" & vbTab, errCnt
    
    
    wscript.quit ''''''''''''''''''''
    
    
    Sub ShowSubFolders(ByVal Folder)
        On Error Resume Next
        For Each Subfolder in Folder.SubFolders
          If err.number <> 0 then
            objLogFile.Writeline "Error " & Left(err.number & space(10), 10) _
                         & ", " & Left(err.description & space(34), 34) _
                         & ",, " & Folder.path
            errCnt = errCnt + 1
            err.clear
            Exit Sub
          End If
          Set objFolder = objFSO.GetFolder(Subfolder.Path)
          call ForEachFolder(objFolder)
          Set colFiles = objFolder.Files
          For Each objFile in colFiles
            call ForEachFile(objFile)
          Next
          ShowSubFolders objFolder
        Next
    End Sub
    
    Sub ForEachFile(ByVal File)
        strPath = File.Path
        FileLength = Right(1E5 + Len(File.name), 5)
        PathLength = Right(1E5 + Len(strPath), 5)
        tiggered = False
    
        If (PathLength-maxPathLength) >0 Then
          tiggered = True
        ElseIf (FileLength-maxFileLength) >0 Then
          tiggered = True
        End If
    
        If tiggered = True Then
          fleCnt = fleCnt + 1
          objLogFile.Writeline "Pathlength:" & PathLength _
                           & ", Filelength:" & FileLength _
                           & "," & space(18) _
                           & ", " &  strPath
        End If
    End Sub
    
    Sub ForEachFolder(ByVal Folder) 
        strPath = Folder.Path
        FolderLength = Right(1E5 + Len(Folder.name), 5)
        FolderDepth = Right(1E5 + UBound(split(strPath, "\")),5)
        PathLength = Right(1E5 + Len(strPath), 5)
        tiggered = False
    
        If (PathLength-maxPathLength) >0 Then
          tiggered = True
        ElseIf (FolderLength-maxFolderLength) >0 Then
          tiggered = True
        ElseIF (FolderDepth-maxFolderDepth) >0 Then
          tiggered = True
        End If
    
        If tiggered = True Then
          flrCnt = flrCnt + 1
          objLogFile.Writeline "Pathlength:" & PathLength _
                           & ", Fldrlength:" & FolderLength _
                           & ", Folderdepth:" & FolderDepth _
                           & ", " &  strPath
        End If
    End Sub
    The value of maxPathLength in the script is what you are looking for (you can raise the number of the other treshholds to 999 if you don't want to use them).
    Note, this script enumerate every file in every folder and subfolders, it can take a while to finish.


    \Rems


    If the path to a folder is more than 255 chacters long, the user will have trouble to explore the subfolders or open the files in that folder. In that case you can create a shared folder of one of the existing folders halfway the long path. Acces through that share, then use Compressedfolders to pack the dieper folders and files.
    .

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Full path length

      Thanks, Rems. Nice looking piece of code here
      I'll run it and let you know...

      Sorin Solomon


      In order to succeed, your desire for success should be greater than your fear of failure.
      -

      Comment


      • #4
        Re: Full path length

        Thank you sorin,
        I wrote the script 2 years ago, for someone who wasn't able to transfer all of her documents from the network to her standalone notebook (via an usb linkcable/protocol), and wasn't also able to burn some of the folders to a DVD or able to compress some paths with WinRar. The sample script finds those files and folders that possibly where not transfered.

        This is not the original script, I don't have that anymore. I re-wrote it yesterday from the things I remembered. It was finished by the time I went to bed or I should say, I finished this script when I thought it is realy time to go . You may have to adjust some details.

        \Rems

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment


        • #5
          Re: Full path length

          Cool, Rems.
          It looks like (surprisingly ) it is doing the job!!
          Can you tell me what the other constants mean?

          Sorin Solomon


          In order to succeed, your desire for success should be greater than your fear of failure.
          -

          Comment

          Working...
          X