Find long file names

Find long file names

19
Basic UserBasic User
19

    Sep 26, 2011#1

    Problem: When you save webpages or favorites, you can inadvertently get files that are longer than MAX_PATH.

    Objective: find files that are longer than 255 characters

    Step 1) get a list of all files dir c:\ /s /b > files.txt

    Step 2) Wanted, a script to possibly select all lines longer than MAX_PATH (255) from a file

    Don't think this sort of thing will work well when the file is 150,000 lines long
    var lineTerminator = "\r\n";
    var str = UltraEdit.activeDocument.selection;
    var resultArr = new Array();
    resultArr = str.split(lineTerminator);

    IS this the way you would parse the file, line by line, put this in a loop
    UltraEdit.activeDocument.gotoLine(1,0);
    selectLine
    get line length
    if line length > 255 write to output window?

    6,686585
    Grand MasterGrand Master
    6,686585

      Sep 27, 2011#2

      Getting the list of files can be also done with UltraEdit from within a script. Here is the script you need. Please read the comments at top of the script.

      Code: Select all

      // Insert here the code of function GetListOfFiles() downloaded
      // from https://www.ultraedit.com/resources/scripts/GetListOfFiles.js
      // Paste only the code of the function without the code for demonstration
      // below the function. If not using English UltraEdit, you have to adapt
      // the values of the 2 string variables sSummaryInfo and sResultsDocTitle
      // at top of function GetListOfFiles().
      
      if (GetListOfFiles(0,"C:\\","*.*",true)) {
      
         UltraEdit.activeDocument.selectAll();
         var asFileNames = UltraEdit.activeDocument.selection.split("\r\n");
      
         UltraEdit.outputWindow.showStatus=false;
         UltraEdit.outputWindow.clear();
         if (UltraEdit.outputWindow.visible == false) {
            UltraEdit.outputWindow.showWindow(true);
         }
      
         var nCount = 0;
         for (var nIndex = 0; nIndex < asFileNames.length; nIndex++) {
            if (asFileNames[nIndex].length > 255) {
               UltraEdit.outputWindow.write(asFileNames[nIndex]);
               nCount++;
            }
         }
         UltraEdit.outputWindow.write("");
         UltraEdit.outputWindow.write(nCount.toString() + " file names longer than 255 characters found.");
      }

      19
      Basic UserBasic User
      19

        Sep 27, 2011#3

        Thanks for showing me the way!
        My current expertise is in DHTML, DOM, HTML, javascript etc. If you have an issue with that kind of web stuff, please do not hesitate to ask.
        I am continually surprised when
        UltraEdit.activeDocument.selectAll();
        var asFileNames = UltraEdit.activeDocument.selection.split("\r\n");
        works on files with over 150,000 lines!

        6,686585
        Grand MasterGrand Master
        6,686585

          Sep 27, 2011#4

          gary_johnson_53 wrote:I am continually surprised when ... works on files with over 150,000 lines!
          As long as there is enough free memory on your computer to hold all the strings in memory, there is no problem.

          I have just thought that when all the files names are stored already in a file, why not simply delete all lines with less than 256 characters to get the list of files with names longer than 255 characters.

          Based on the Perl regular expression posted by pietzcker at How to delete all lines not containing specific word or string or expression? the search string required for this job is ^(?!.{256}).*$\r\n and the replace string is simply an empty string.

          19
          Basic UserBasic User
          19

            Sep 27, 2011#5

            Thanks, This stuff is like magic.