Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find filenames or folder names that have more than 256 characters and list them into a txt file with the path.

Hi,

Find filenames or folder names that have more than 256 characters and list them into a txt file with the path.
So i can see them and later browse to the path and delete some words.

Regards
Sharath
Avatar of OrbitMed
OrbitMed

You  can use a vbscript:

Set ofso = CreateObject("Scripting.FileSystemObject")
Set obshell = CreateObject("Wscript.shell")
Set path = ofso.GetFolder(obshell.CurrentDirectory)
Set txtfile = ofso.CreateTextFile("Files.txt",1)

Set obfolder = path.Files

For Each file In obfolder

      If file.Name <> "File List.vbs" Then
      txtfile.writeline file.Name
      End If
Next

txtfile.close
Lets try that again.

Set ofso = CreateObject("Scripting.FileSystemObject")
Set obshell = CreateObject("Wscript.shell")
Set path = ofso.GetFolder(obshell.CurrentDirectory)
Set txtfile = ofso.CreateTextFile("Files.txt",1)

Set obfolder = path.Files

For Each file In obfolder
      strlen = Len(fine.name)
            If strlen = 256 Then
                  If file.Name <> "File List.vbs" Then
                  txtfile.writeline file.Name
                  End If
            End If
Next

txtfile.close
Avatar of bsharath

ASKER

I tried the 2nd script

I get this
---------------------------
Windows Script Host
---------------------------
Script:      D:\Morethan256.vbs
Line:      9
Char:      7
Error:      Object required: 'fine'
Code:      800A01A8
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------

Where should i mention the path to let it scan
Avatar of AmazingTech
Last folder/file in each line is greater than 256 in length.
Const ForWriting = 2
StartFolder = "C:\Files"
LogFile = "C:\256Length.log"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile(LogFile, ForWriting, True)
Call CheckFolder(StartFolder)
 
Set objFSO = Nothing
objLogFile.Close
 
Sub CheckFolder(Folder)
    Set ArrFiles = objFSO.GetFolder(Folder).Files
    For Each File In ArrFiles
        IF Len(File.name) > 256 THEN objLogFile.WriteLine File
    Next
    
    IF Len(Folder) - instrrev(Folder,"\") > 256 THEN objLogFile.WriteLine Folder
 
    Set ArrSubFolders = objFSO.GetFolder(Folder).SubFolders
    For Each SubFolder In ArrSubFolders
        call CheckFolder(SubFolder)
    Next
End Sub

Open in new window

Yeah I type fine instead of file on the one line and you'll need to change it so the it's >= instead of just equal. Just drop it in a folder and run it and a text file will appear in that folder.
AT i tried with some long named files. But none came into the log
This one will work, just drop in the directory and run it.

Set ofso = CreateObject("Scripting.FileSystemObject")
Set obshell = CreateObject("Wscript.shell")
Set path = ofso.GetFolder(obshell.CurrentDirectory)
Set txtfile = ofso.CreateTextFile("Files.txt",1)

Set obfolder = path.Files

For Each file In obfolder
      strlen = Len(file.name)
            If strlen >= 256 Then
                  If file.Name <> "File List.vbs" Then
                  txtfile.writeline file.Name
                  End If
            End If
Next

txtfile.close
ASKER CERTIFIED SOLUTION
Avatar of AmazingTech
AmazingTech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The actual limitation for full path as I remember it is 260 characters.
THANK U AT worked fine

OrbitMed i dont know why when i moved any folder on the script it creates the txt file but no data gets logged. I even noticed that there is no process running when the script runs...
Any ways thanks for the help
THANK U AT worked fine

OrbitMed i dont know why when i moved any folder on the script it creates the txt file but no data gets logged. I even noticed that there is no process running when the script runs...
Any ways thanks for the help
If you wanted full path greater than 256.
Const ForWriting = 2
StartFolder = "C:\Files"
LogFile = "C:\256Length.log"
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile(LogFile, ForWriting, True)
Call CheckFolder(StartFolder)
 
Set objFSO = Nothing
objLogFile.Close
 
Sub CheckFolder(Folder)
    Set ArrFiles = objFSO.GetFolder(Folder).Files
    For Each File In ArrFiles
        IF Len(File) > 256 THEN objLogFile.WriteLine File
    Next
    
    IF Len(Folder) > 256 THEN objLogFile.WriteLine Folder
 
    Set ArrSubFolders = objFSO.GetFolder(Folder).SubFolders
    For Each SubFolder In ArrSubFolders
        call CheckFolder(SubFolder)
    Next
End Sub

Open in new window

AT what is the difference betwen the accepted solution and the solution u posted now
It checks for full paths greater than 256 characters.

C:\Folder1\Folder2\Folder3\Folder4\Whatever filename which maybe super long.txt

I thought you wanted to shorten long lengths because of this potential error with Path lengths greater than 260 characters:

http://support.microsoft.com/kb/816841/en-us

http://support.microsoft.com/kb/883721/en-us
The accepted solution in this post will this find the filename or folder name that is longer than 256?
The accepted solution in this post will this find the filename or folder name that is longer than 256?
The accepted solution is actually each filename or folder name greater than 25 characters. I put that for you to try and see if are getting anything into the log. 256 characters for just 1 filename or 1 folder name is rare. IE Favorites could have many of these but even they don't have that much.
ok THX
ok THX
Find filenames or folder names that have more than 256 characters ...

I have been trying your script but have errors can you help?