Last active
August 29, 2015 14:15
-
-
Save gitcrtn/ede3079518255fa6d34d to your computer and use it in GitHub Desktop.
ファイルやフォルダのパスを取得
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: shift-jis -*- | |
# http://tsumo-blog.blogspot.jp/2012/03/windows.html から引用し、一部変更 | |
# 右クリックメニューから、ファイルやフォルダのパスをクリップボードに取得できるようになります | |
import sys | |
import os.path | |
def copyToClipboad( msStr ): | |
import win32clipboard | |
import win32con | |
try: | |
win32clipboard.OpenClipboard() | |
win32clipboard.EmptyClipboard() | |
win32clipboard.SetClipboardData(win32con.CF_TEXT, msStr) | |
win32clipboard.CloseClipboard() | |
return True | |
except: | |
return False | |
return True | |
if __name__=='__main__': | |
if len(sys.argv)==2: | |
sys.exit() | |
file_path_strings = [] | |
argv_count = len(sys.argv) | |
for i,argv in enumerate(sys.argv): | |
if i == 0: | |
continue | |
if i < argv_count - 1: | |
file_path_strings.append(argv) | |
else: | |
mode = argv | |
file_path = ' '.join(file_path_strings) | |
if mode=='UNIX': | |
file_path = file_path.replace('\\','/') | |
path = file_path | |
elif mode=='UNC': | |
path = file_path | |
if len(sys.argv)==4: | |
if sys.argv[3]=='-dir': | |
path = os.path.dirname(file_path) | |
copyToClipboad(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
;============================================== | |
; paste UNC file path to clipboard | |
;============================================== | |
[HKEY_CLASSES_ROOT\*\shell\unc_file_path] | |
[HKEY_CLASSES_ROOT\*\shell\unc_file_path] | |
@="CopyPath(UNC)" | |
[HKEY_CLASSES_ROOT\*\shell\unc_file_path\command] | |
[HKEY_CLASSES_ROOT\*\shell\unc_file_path\command] | |
@="C:\\Python27\\pythonw.exe C:\\scripts\\winPathCopy.py %1 UNC" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
;============================================== | |
; paste UNC folder path to clipboard | |
;============================================== | |
[HKEY_CLASSES_ROOT\Directory\shell\unc_folder_path] | |
[HKEY_CLASSES_ROOT\Directory\shell\unc_folder_path] | |
@="CopyPath(UNC)" | |
[HKEY_CLASSES_ROOT\Directory\shell\unc_folder_path\command] | |
[HKEY_CLASSES_ROOT\Directory\shell\unc_folder_path\command] | |
@="C:\\Python27\\pythonw.exe C:\\scripts\\winPathCopy.py %1 UNC" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
;============================================== | |
; paste UNIX file path to clipboard | |
;============================================== | |
[HKEY_CLASSES_ROOT\*\shell\unix_file_path] | |
[HKEY_CLASSES_ROOT\*\shell\unix_file_path] | |
@="CopyPath(UNIX)" | |
[HKEY_CLASSES_ROOT\*\shell\unix_file_path\command] | |
[HKEY_CLASSES_ROOT\*\shell\unix_file_path\command] | |
@="C:\\Python27\\pythonw.exe C:\\scripts\\winPathCopy.py %1 UNIX" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Windows Registry Editor Version 5.00 | |
;============================================== | |
; paste UNIX folder path to clipboard | |
;============================================== | |
[HKEY_CLASSES_ROOT\Directory\shell\unix_folder_path] | |
[HKEY_CLASSES_ROOT\Directory\shell\unix_folder_path] | |
@="CopyPath(UNIX)" | |
[HKEY_CLASSES_ROOT\Directory\shell\unix_folder_path\command] | |
[HKEY_CLASSES_ROOT\Directory\shell\unix_folder_path\command] | |
@="C:\\Python27\\pythonw.exe C:\\scripts\\winPathCopy.py %1 UNIX" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment