When the contents of the folder are messed up by some work, it may be tempting to rename them all at once.
What was made.
As a request,
Add a button to the toolbar on Tablacus Explorer.
Right-click on it and select "Add" to open the dialog.
//name:(suitable)
//type:JScript
//option:(Code below)
//icon:(suitable)
var FV = GetFolderView(Ctrl, pt);
var Selected = FV.SelectedItems();
if (Selected) {
var dat = "";
for (var i = 0; i < Selected.Count; i++) {
dat += "\"" + Selected.Item(i).Path + '\" ';
}
if (dat == "") {
alert("not selected.");
} else {
wsh.Run("C:/foo/Src/Python27/python.exe C:/foo/Sample/rename_selected.py " + dat);
}
}
//If you copy the code"add to"so"OK"
As for the contents
--Get a list of selected items --Extract the full path from the list --Combine full paths into strings like "(full path 1)" "(full path 2)" ... --Take a join string as an argument and feed it to the python script described later as an argument.
Create a script in your own execution environment.
rename_selected.py
# coding: Shift_JIS
import os
import sys
def get_selected_list(param):
target_list = []
if len(param) > 1:
for folder in param:
folder = unicode(folder, encoding='shift-jis').replace(unicode("\\", encoding='shift-jis'), "/")
target_list.append(folder)
return target_list
def rename_folder(src_path):
dst_path = src_path
#The replacement rule is appropriate, the following is an example of trimming a specific word
#It's a full pass match, so it's evil if you get caught in the middle
dst_path = dst_path.replace(unicode(" -copy", encoding='shift-jis'), "")
dst_path = dst_path.replace(unicode(" (1)", encoding='shift-jis'), "")
dst_path = dst_path.replace(unicode("_yymmdd", encoding='shift-jis'), "")
if not os.path.isdir(dst_path):
os.rename(src_path, dst_path)
if __name__ == "__main__":
folder_list = get_selected_list(sys.argv)
for folder in folder_list:
rename_folder(folder)
The contents are so decent that it was hard to play with the Japanese file system. (I said I wanted to do what I wanted, but I didn't fight with particularly advanced regular expressions)
I searched for Tablacus Explorer to extend the script, but as a matter of course, JScript What is .aspx)?
So, I wanted to minimize the description in JScript and throw the possible processing to python, but it is annoying to google with "(keyword) JScript -javascript" ...
And when you get to know a little, the following differences will gradually come into effect ... Notes on porting MDIE scripts to Tablacus Explorer. Object contrast, etc.
I managed to reach the following and made a safe call.
-[I wrote three scripts that were requested at a certain place. -Copy folder structure only to clipboard var CreateFolderOnly2 = function (path, dest, Items, nAdd) {api.SetWindowText (te.hwnd, path); CreateFolder (dest);…](http://tablacus.hatenablog.com/ entry / 2015/07/14/224503) -[Blog that records daily notes on programming](http://kujirahand.com/blog/index.php?JScript%E3%81%A7%E3%82%B3%E3%83%9E % E3% 83% B3% E3% 83% 89% E5% AE% 9F% E8% A1% 8C)
In terms of elemental technology, the following were required.
--Get selected items on Tablacus --Get full path of selected item --alert debug --Calling an external script from JScrip --Passing Japanese arguments including spaces and symbols -(I thought there was a current path, but I didn't need it, but I got it)
I wonder why I still can't get out of python2.7 hell
Recently I wrote a little script on Tablacus Explorer, and I often write a script that calls a local execution system from there. It's completely the same as doing it with bookmarklet + self-made stray add-on on the browser.
Personally, how can I connect GUI processing to CUI and programming language processing? It's important, so I hope I can overcome each barrier in a good way.
By the way, I could have created a separate GUI app, but I didn't. I wanted to complete it among the apps that I usually open, or I didn't want to keep the extra apps running in the small display space. It's enough to add a button to the edge of the filer.
that's all.
Recommended Posts