Pass the selected item in Tablacus Explorer from JScript to python and rename it all at once

Introduction

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. renamer.gif

As a request,

Implementation

Button creation and JScript

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.

Rename with python

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)

Finally the point of each implementation

Write the process for the selected target on Tablacus Explorer in python

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)

The pain of fighting the Japanese file system

I wonder why I still can't get out of python2.7 hell

Impressions

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

Pass the selected item in Tablacus Explorer from JScript to python and rename it all at once
[Python] How to save the installed package and install it in a new environment at once Mac environment
[python] Send the image captured from the webcam to the server and save it
I want to replace the variables in the python template file and mass-produce it in another file.
It is easy to execute SQL with Python and output the result in Excel
Pass an array from PHP to PYTHON and do numpy processing to get the result
[C / C ++] Pass the value calculated in C / C ++ to a python function to execute the process, and use that value in C / C ++.
Recursively get the Excel list in a specific folder with python and write it to Excel.
A Python script that goes from Google search to saving the Search results page at once
An easy way to view the time taken in Python and a smarter way to improve it
Put Ubuntu in Raspi, put Docker on it, and control GPIO with python from the container
Try to make it using GUI and PyQt in Python
[Python] I installed the game from pip and played it
How to get all the keys and values in the dictionary
Object-oriented in C: Refactored "○ ✕ game" and ported it to Python
Pass OpenCV data from the original C ++ library to Python
Read the old Gakushin DC application Word file (.doc) from Python and try to operate it.
[Python] The role of the asterisk in front of the variable. Divide the input value and assign it to a variable
Determine the date and time format in Python and convert to Unixtime
How to install OpenCV on Cloud9 and run it in Python
How to pass and study the Python 3 Engineer Certification Basic Exam
How to get followers and followers from python using the Mastodon API
How to use the asterisk (*) in Python. Maybe this is all? ..
Read big endian binary in Python and convert it to ndarray
Convert the result of python optparse to dict and utilize it
Change the active version in Pyenv from anaconda to plain Python
How to display bytes in the same way in Java and Python
Python --Get bitcoin rate BTC / JPY from bitflyer at regular intervals and save it to a file
[Python / Jupyter] Translate the comment of the program copied to the clipboard and insert it in a new cell
Output the report as PDF from DB with Python and automatically attach it to an email and send it
How to input a character string in Python and output it as it is or in the opposite direction.
I want to pass an argument to a python function and execute it from PHP on a web server
In the python command python points to python3.8
Combine multiple dictionaries and add multiple elements at once, safely and non-destructively in Python
How to write the correct shebang in Perl, Python and Ruby scripts
[Python] Sweet Is it sweet? About suites and expressions in the official documentation
How to get the date and time difference in seconds with python
I set the environment variable with Docker and displayed it in Python
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
Connect to postgreSQL from Python and use stored procedures in a loop.
The file name was bad in Python and I was addicted to import
For the first time in Numpy, I will update it from time to time
[At Coder] What I did to reach the green rank in Python
Use the LibreOffice app in Python (2) Manipulate calc (from macros and externals)
Use python's pixivpy to download all the works of a specific user from pixiv at once (including moving)
An engineer who has noticed the emo of cryptography is trying to implement it in Python and defeat it