Find long file names

Help with writing and running scripts

Find long file names

Postby gary_johnson_53 » Mon Sep 26, 2011 4:36 pm

Problem: When you save web pages 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 ouptut window?
User avatar
gary_johnson_53
Newbie
 
Posts: 9
Joined: Sat Mar 12, 2005 12:00 am

Re: Find long file names

Postby Mofi » Tue Sep 27, 2011 12:24 am

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 http://www.ultraedit.com/files/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.");
}
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find long file names

Postby gary_johnson_53 » Tue Sep 27, 2011 9:35 am

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!
User avatar
gary_johnson_53
Newbie
 
Posts: 9
Joined: Sat Mar 12, 2005 12:00 am

Re: Find long file names

Postby Mofi » Tue Sep 27, 2011 11:52 am

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.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find long file names

Postby gary_johnson_53 » Tue Sep 27, 2011 1:10 pm

Thanks, This stuff is like magic.
User avatar
gary_johnson_53
Newbie
 
Posts: 9
Joined: Sat Mar 12, 2005 12:00 am


Return to Scripts