Okay, then we can't use a regular expression Replace in Files. It would be perhaps possible with a regular expression Replace in Files, but this depends on the file sizes and is therefore not secure for usage on any text file of any file size.
Here is the code of a macro which first runs a recursive
Find in Files
- on the specified directory C:\Temp\ (backslash at end is important)
- with the specified file type specification *.txt (can be also just * for all files or a list of file types separated with a semicolon)
- with an empty search string
to get output into a results file a list of file names with full path found in the directory tree starting in
C:\Temp\.
English UltraEdit v23.20 appends at end of the file names list the summary information
Code: Select all
Search complete, found '' x time(s). (0 file(s)).
This summary information is selected with a case-sensitive
Find for
Search complete, in upwards direction with selecting everything from bottom of file up to beginning of found string. The selected block is deleted if this string could be really found. The search string must be modified if not using English UltraEdit. Run manually a
Find in Files with an empty search string in
Files listed to see what your UltraEdit in your configuration outputs.
The results file created by
Find in Files is a Unicode file since UE v12.00 and UEStudio v5.50. For that reason the results file with the list of file names is converted to ASCII/ANSI before processing the file names.
In a loop executed until caret reaches end of the results file the next file name with path is selected and the file is opened. In the opened file with caret at top a check is made if the first character is a carriage return or a line-feed in which case a single regular expression
Replace is executed to delete the empty line(s) at top of the file. The modified file is saved and next closed. Files starting with any other character than CR or LF are closed without being modified at all, i.e. keep their last modification time.
Finally the results file with the list of file names is closed without saving it.
The file with the file names must end with a line termination to reach with
Key HOME and
Key DOWN ARROW the end of the file. But this is definitely the case on list file created with
Find in Files.
Code: Select all
InsertMode
ColumnModeOff
HexOff
UltraEditReOn
FindInFiles Recursive "C:\Temp\" "*.txt" ""
Find MatchCase Up Select "Search complete,"
IfSel
Delete
EndIf
Top
UnicodeToASCII
Loop 0
IfEof
ExitLoop
EndIf
StartSelect
Key END
Open "^s"
Top
IfCharIs 13
Find MatchCase RegExp "[^r^n]+"
Replace ""
Save
Else
IfCharIs 10
Find MatchCase RegExp "[^r^n]+"
Replace ""
Save
EndIf
EndIf
CloseFile NoSave
EndSelect
Key HOME
Key DOWN ARROW
EndLoop
CloseFile NoSave