Advertisement
Guest User

FindLongPaths.vbs

a guest
Dec 28th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getfolderitem(folder, byref root)
  2.   dim fo, fi
  3.   root = false
  4.   set fo = folder.parentfolder
  5.   set fi = fo.parsename(folder.title)
  6.   if fi is nothing then
  7.     for each fi in fo.items
  8.       if fi.name = folder.title then
  9.         root = true
  10.         set getfolderitem = fi
  11.         exit function
  12.       end if
  13.     next
  14.     set getfolderitem = nothing
  15.   else
  16.     set getfolderitem = fi
  17.   end if
  18. end function
  19.  
  20. function itempath(fi)
  21.   dim path, fitm, root
  22.   if instr(fi.path, "~") > 0 then
  23.     set fitm = fi
  24.     path = fitm.name
  25.     do
  26.       root = false
  27.       set fitm = getfolderitem(fitm.parent, root)
  28.       if fitm is nothing then exit do
  29.       if root then
  30.         path = fitm.path & path
  31.         exit do
  32.       else
  33.         path = fitm.name & "\" & path
  34.       end if
  35.     loop
  36.     itempath = path
  37.   else
  38.     itempath = fi.path
  39.   end if
  40. end function
  41.  
  42. sub check(path)
  43.   dim fo, fi
  44.   on error resume next
  45.   set fo = sa.namespace(path)
  46.   if err.number = 0 then
  47.     for each fi in fo.items
  48.       path = itempath(fi)
  49.       if len(path) > 259 then
  50.         if gui then
  51.           txt = txt & path & vbcrlf
  52.         else
  53.           wscript.echo path
  54.         end if
  55.       else
  56.         if fi.isfolder then check(fi.path)
  57.       end if
  58.     next
  59.   elseif gui then
  60.     txt = txt & path & vbcrlf
  61.   else
  62.     wscript.echo path
  63.   end if
  64.   on error goto 0
  65. end sub
  66.  
  67. set sh = createobject("wscript.shell")
  68. set fs = createobject("scripting.filesystemobject")
  69. set sa = createobject("shell.application")
  70. if wscript.arguments.count = 0 then
  71.   wscript.echo "FindLongPaths {RootPath}"
  72.   wscript.quit
  73. end if
  74. gui = instrrev(lcase(wscript.fullname), "\wscript.exe") > 0
  75. txt = ""
  76. check(wscript.arguments(0))
  77. if gui then
  78.   if txt <> "" then
  79.     fn = sh.specialfolders("desktop") & "\Long Paths " & _
  80.       replace(replace(now, "/", "-"), ":", ".") & ".txt"
  81.     set f = fs.createtextfile(fn, true, true)
  82.     f.write(txt)
  83.     f.close
  84.     sh.run """" & fn & """", 1
  85.   else
  86.     wscript.echo "No long path found."
  87.   end if
  88. end if
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement