Find backwards and copy last directory name to clipboard

Help with writing and playing macros

Find backwards and copy last directory name to clipboard

Postby sas2000 » Sun Nov 26, 2006 2:38 am

Hi, I'm using Ultraedit to write Robocopy batch scripts. I start my batch files pasting a list of directories (that I copy on my file manager) as :

C:\Windows
C:\Program Files\Opera

Macro should copy the name of present directory or subdirectory to clipboard :

Code: Select all
C:\Windows               macro must copy to clipboard "Windows"
C:\Program Files\Opera   macro must copy to clipboard "Opera"

The problem that I've found is that I don't know how to configure my macro to find backward for "\" to be able to use :

Code: Select all
Key END
Find BACKWARD "\"            <-- PROBLEM
Key LEFT ARROW
Key RIGHT ARROW
StartSelect
Key END
Copy
EndSelect
Key DOWN ARROW

May you help me ? , thanks.
User avatar
sas2000
Newbie
 
Posts: 9
Joined: Sat Aug 05, 2006 11:00 pm

Re: Find backwards and copy last directory name to clipboard

Postby Mofi » Sun Nov 26, 2006 1:38 pm

Find backwards means find upwards:

Key END
Find Up "\"
Key LEFT ARROW
Key RIGHT ARROW
StartSelect
Key END
Copy
EndSelect
Key DOWN ARROW

If you already have a file with a list of directory names it is much faster to convert them with a regular expression search and replace.

The following macro

  • copies the content of the current file (list of directories) to a new ASCII file with DOS line terminations,
  • adds also a DOS line termination at the end of the file if the last line has not already a line termination,
  • removes trailing spaces (for security),
  • deletes everything before last backslash at every line and
  • copies the rest back to current clipboard before discarding the new temp file.
Well, you can modify the replace string to get the line you need in the batch file with a single search and replace all.

InsertMode
ColumnModeOff
HexOff
UnixReOff
SelectAll
Copy
NewFile
UnicodeToASCII
UnixMacToDos
Paste
IfColNum 1
Else
"
"
EndIf
Top
TrimTrailingSpaces
Find RegExp "%*\^([~\^p]+^)$"
Replace All "^1"
SelectAll
Copy
CloseFile NoSave

Add UnixReOn or PerlReOn (v12+ of UE) at the end of the macro if you do not use UltraEdit style regular expressions by default - see search configuration. Macro command UnixReOff sets the regular expression option to UltraEdit style.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4062
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Find backwards and copy last directory name to clipboard

Postby sas2000 » Sun Nov 26, 2006 8:26 pm

Thanks :!:
User avatar
sas2000
Newbie
 
Posts: 9
Joined: Sat Aug 05, 2006 11:00 pm


Return to Macros