Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@take-takashi
Created December 20, 2011 07:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save take-takashi/1500596 to your computer and use it in GitHub Desktop.
Save take-takashi/1500596 to your computer and use it in GitHub Desktop.
「選択エントリーをテキストエディタで一気にリネーム」を改良したもの
//!*script
// This script is in the public domain.
// PPc 用スクリプト。
// 選択エントリーをテキストエディタで一気にリネーム。
//
// PPx側でエディター設定していればそれを使う。
// 指定なしorエディタが存在しない場合はPPeで編集する。
var editor = PPx.Extract("%'editor'");
// ファイル操作
var fso = new ActiveXObject('Scripting.FileSystemObject');
editor = fso.GetAbsolutePathName(editor);
if(PPx.EntryFirstMark != 1){
PPx.Echo('マークされたエントリがありません');
PPx.Quit();
}
// マークしたファイルのリストを取得
var listFile = PPx.Extract('%aFCN');
if(fso.FileExists(editor)){
// 指定エディタで起動
var command = '%Obsq \"' + editor + '\" \"' + listFile + '\"';
PPx.Execute(command);
}else{
// 指定エディタが設定されていない場合は PPe で
PPx.Execute('*edit \"' + listFile + '\"');
}
// 編集したファイルを読む
var newFileNames = [];
if(fso.FileExists(listFile)){
var f = fso.OpenTextFile(listFile, 1);
while(! f.AtEndOfStream){
newFileNames.push(f.ReadLine());
}
f.close();
}else{
PPx.Echo('リネームデータを取得できませんでした');
PPx.Quit();
}
// エントリのリネーム
var dir = PPx.Extract('%1%\\');
for(var i = 0; true; i++){
var oldName = dir + PPx.EntryName;
var newName = dir + newFileNames[i];
if ( newFileNames[i]
&& newName != oldName
&& fso.FileExists(oldName)
&& (!fso.FileExists(newName))
){
fso.GetFile(oldName).Move(newName);
}else{
if(newName != oldName){
PPx.Echo(PPx.EntryName + ' のリネームに失敗しました。\n名前の重複などを確認してください\n'+newName+'\n'+oldName);
}
}
PPx.EntryMark = 0;
if(PPx.EntryNextMark == 0) break;
}
PPx.Quit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment