Page 1 of 2

Mass rename via external text editor

Posted: 10 Apr 2018 09:50
by highend
XYplorer provides "Rename Special - Edit Item Names..." which is nice for visually renaming multiple files
at once.

The drawback is, it does lack relevant editor capabilities like multiple cursors, search and replace, etc.

This little tool does the following:
- It is invoked via a .xys script
- It passes the file that was written by the .xys script to an external text editor of your choice
- When the file is saved (from inside your text editor), it updates the content of the "Edit Item Names..." window
- It automatically activates this window (if configured via the .ini file - It's ON by default!)
- It monitors the "Edit Item Names..." window and quits itself, once this window was closed

When the script is started for the first time, it creates an .ini file with the same base name as the script after using a "startup wizard".
This will ask you to find and select two things (and opens a file requester for both):
01. Find and select the "xyColumnEdit.exe" file
02. Find and select the text editor (that should support a "column edit mode") to use

The .ini file could e.g. look like this afterwards:

Code: Select all

[General]
Tool=@Tools\ColumnEdit\xyColumnEdit.exe
Editor=C:\Program Files (x86)\Sublime Text\sublime_text.exe
ActivateWindow=1
Temp=R:\TEMP
Tool, Editor and Temp entries support portable paths!
The root path is <xypath> and in this sample .ini, the Tool entry was saved relative to it.
The script would resolve it internally to <xypath>\@Tools\ColumnEdit\xyColumnEdit.exe...

The ActivateWindow and Temp entries are using default entries (1 and the %TEMP% environment variable) on first script start.
If you would like the script to save the file that contains all items to rename in a different location you could change the Temp entry in the .ini file afterwards.

If you don't want to auto-activate XY's 'Edit Item Names' window, set ActivateWindow to 0.

The attachment contains the .xys script ColumnEdit.xys and the compiled AHK script xyColumnEdit.exe...

Please note that you can't use your old .ini file when switching to v1.3 (or up)!

Current version:
ColumnEdit_v1.3.zip

Re: Mass rename via external text editor

Posted: 10 Apr 2018 10:13
by highend

Code: Select all

v1.3 - Moved .ini logic to XY script
       Convert Unix line endings to Windows
       Try to delete the temp file on exit

v1.2 - Added EM_EXLIMITTEXT

v1.1 - Added #MaxMem 512

Re: Mass rename via external text editor

Posted: 06 May 2020 15:05
by kotlmg

Code: Select all

if !(get("CountSelected")) { status "No item(s) selected, aborted!", "8B4513", "stop"; end true; }
    writefile("%TEMP%\~ColumnEdit.txt", <get SelectedItemsNames <crlf>>, , "utf8bom");
    run "<full path to ColumnEdit.exe>", "%TEMP%";
    #147;
hello sir,
i want to modify the above code with editplus 3 as external text editor.
editplus is avaible in "C:\Program Files (x86)\EditPlus 3\editplus.exe".
when i replace "<full path to ColumnEdit.exe>" with "C:\Program Files (x86)\EditPlus 3\editplus.exe" above script is giving error editplus not found.
is there any syntax wrong in the above script?

Re: Mass rename via external text editor

Posted: 06 May 2020 16:26
by highend
*cries*
Full path to ColumnEdit.exe, not to your editor^^

Your editor is defined in the ColumnEdit.ini file
The .ini file looks like this (it is created automatically on the first start of this tool!):

Re: Mass rename via external text editor

Posted: 06 May 2020 17:07
by kotlmg
i have written the code as
if !(get("CountSelected")) { status "No item(s) selected, aborted!", "8B4513", "stop"; end true; }
writefile("%TEMP%\~ColumnEdit.txt", <get SelectedItemsNames <crlf>>, , "utf8bom");
run "C:\Program Files (x86)\EditPlus 3\editplus.exe", "%TEMP%";
#147;
i am getting the attached error.

Re: Mass rename via external text editor

Posted: 06 May 2020 17:17
by highend
Apart from the not found error (which you can solve by using e.g. tripple double quotes instead of single ones (the path contains spaces)...
Read my last post and the first post as often as necessary to understand that you need to run ColumEdit.exe in that script^^

Re: Mass rename via external text editor

Posted: 06 May 2020 17:34
by kotlmg
by adding triple quotes i am not getting error. i want to send selected files for renaming to editplus not to columnedit.exe


basically i want to edit selected file names with editplus not with columnedit.exe

Re: Mass rename via external text editor

Posted: 06 May 2020 17:50
by highend
*grrrr*
How often do I need to say that you NEED to send them to ColumnEdit? oO
That little helper tool forwards them to the editor of your choice defined in the belonging .ini file, NOT in the XY script^^

Re: Mass rename via external text editor

Posted: 06 May 2020 17:57
by kotlmg
i have written the code as
if !(get("CountSelected")) { status "No item(s) selected, aborted!", "8B4513", "stop"; end true; }
writefile("%TEMP%\~ColumnEdit.txt", <get SelectedItemsPathNames <crlf>>, , "utf8bom");
run """C:\Users\M.K.RAO\Downloads\ColumnEdit_v1.0(1)\xyColumnEdit.exe""", "%TEMP%";
sendkeys "^a^v";
#147;

columnedit.exe is eaten away by my anti virus software.
columnedit.exe is treated as virus. it is being quarantined.
that is the problem.

Re: Mass rename via external text editor

Posted: 06 May 2020 18:02
by highend
Then create an exception for it or ditch the dumb antivirus tool?

Re: Mass rename via external text editor

Posted: 06 May 2020 19:53
by kotlmg
there is some problem with ColumnEdit.exe in this page. it is quarantined by antivirus.
hence i copied ColumnEdit.exe from the following page

viewtopic.php?f=7&t=18745&hilit=ColumnEdit.exe&start=30

edited the settings as
[General]
Editor=C:\Program Files (x86)\EditPlus 3\editplus.exe
ActivateEditItemNamesWindow=0

and wrote the code as
if !(get("CountSelected")) { status "No item(s) selected, aborted!", "8B4513", "stop"; end true; }
writefile("%TEMP%\~ColumnEdit.txt", <get SelectedItemsNames <crlf>>, , "utf8bom");
run """C:\xyColumnEdit_v1.2\xyColumnEdit.exe""", "%TEMP%";
#147;
and
it is perfectly working now.

Re: Mass rename via external text editor

Posted: 25 Oct 2020 22:09
by WirlyWirly
This is awesome! I've always thought it would be nice to edit filenames in my editor, but never got around to writing out a script. Now that I've tried it, I regret not figuring this out years ago!

For anyone reading this, there's a v1.2, which isn't mentioned in the OP...

This script works really well, however I'm having one small issue; My editor (Vim via GitBash) applies an invisible EOL (EndofLine) character to every file it saves. When the contents of '~ColumnEdit.txt' are pasted into the the Edit Item Names... window, this (normally invisible) EOL character results in a visible and corrupted new line. Unless I delete that blank line, xyplorer errors out when trying to apply the name change. This only applies when renaming 1 file, but naming many works fine. Pretty weird.

It's not that big of a deal, especially since it only applies when renaming 1 file (which I doubt I need my editor to do) and also because I know vim isn't very popular for windows users. Just thought I'd point it out if you ever push a v1.3 and want to suffer through some debugging!

Anyways, thanks a bunch highend, this is a really neat script! :oops:

P.S
In the spirit of keeping things portable, It'd be neat to move all the configuration into the .xys file, which will then generate a .ini before launching the .exe. This way we could use relative paths (<xypath>, <xyscripts>, etc..) for the editor, instead of hard-coding the path into the .ini.

Also, deleting the temp '~ColumnEdit.txt' file or keeping it alongside the .xys/.ini/.exe instead would be neat. Not a huge deal, but again not leaving anything behind is the magic of portability.

Re: Mass rename via external text editor

Posted: 25 Oct 2020 22:19
by highend
When the contents of the temp.txt file are pasted into the the Edit Item Names... window, this (normally invisible) EOL character results in a visible and corrupted new line.
A screenshot that shows that problem would be nice...

Re: Mass rename via external text editor

Posted: 25 Oct 2020 22:38
by WirlyWirly
Might be a little hard to see a blank line in screenshots, but here goes!

Firstly, when you rename >1 file, there is a blank line at the end (You can see my cursor on it when I press ctrl+a)...
Image

this results in no problems (As you can see by the icons)...
Image

However, when only renaming 1 file, the new line is there, but it's not being picked up as text (My cursor stops before the blank line instead of on it when I press ctrl+a)...
Image

If I don't manually delete this line, the rename fails (as you can see by the un-matched icon on the right)...
Image
Image

Again, not a big deal, just something I ran into right off the bat. Not sure if other vim users would experience this (More likely yes since my configuration is pretty default/vanilla), just thought I'd mention it.

Here's the two '~ColumnEdit.txt' files if you're interested. I opened the _broken one in notepad++, ctrl+a then copied the text, and finally pasted it into the window. I was able to reproduce the problem.

Re: Mass rename via external text editor

Posted: 25 Oct 2020 22:51
by highend
No, that doesn't really help. Send me the temp txt file after saving it via vim. Maybe via a dropbox share?