簡単に作れると思って臨んだのですが意外と長い。
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
<job> | |
<script> | |
arg = WScript.Arguments | |
fs = new ActiveXObject('Scripting.FileSystemObject') | |
shell = new ActiveXObject('WScript.Shell') | |
// フォルダ、ファイルのリストを取得するための変数&関数定義 | |
gsf2 = fs.GetSpecialFolder(2) | |
getDirList = function(path){ return getDirFileList(path) } | |
getFileList = function(path){ return getDirFileList(path,true) } | |
getDirFileList = function(path,swFile){ | |
var 一時Path = gsf2+'/'+fs.getTempName() | |
shell.Run('cmd /C dir /A'+(swFile?'-':'')+'D /B "'+path+'" > "' + 一時Path + '"' , 0 , true) | |
with(fs.OpenTextFile(一時Path)){ var list = AtEndOfStream ? [] : ReadAll().split('\r\n'); Close() } | |
list.pop() | |
fs.DeleteFile(一時Path) | |
return list | |
} | |
reg = /hoge/ | |
// ドロップされたアイテムの数だけループする | |
for(i=0,L=arg.length;i<L;i++){ | |
path = arg(i) | |
name = fs.GetBaseName(path) | |
if(fs.FileExists(path)){ | |
// ファイルの場合 | |
// 名前にregがmatchしない場合は無視 | |
if(!name.match(reg)){continue} | |
pathDest = fs.GetParentFolderName(path) + '\\' + name.replace(reg,'fuga') + '.' + fs.GetExtensionName(path) | |
fs.MoveFile(path, pathDest) | |
}else if(fs.FolderExists(path)){ | |
// フォルダの場合 | |
pathDest = fs.GetParentFolderName(path) + '\\' + name.replace(reg,'fuga') | |
if(name.match(reg)){ | |
fs.MoveFolder(path, pathDest) | |
// 改名が完了するまで待つ | |
while(!fs.FolderExists(pathDest)){ WScript.Sleep(10) } | |
} | |
// フォルダなら中身に対しても自身を実行する | |
フォルダリスト = getDirList(pathDest) | |
for(j=0,jL=フォルダリスト.length;j<jL;j++){ | |
shell.run('cscript "'+WScript.ScriptFullName+'" "'+pathDest+'\\'+フォルダリスト[j]+'"', 1, true) | |
} | |
ファイルリスト = getFileList(pathDest) | |
for(j=0,jL=ファイルリスト.length;j<jL;j++){ | |
shell.run('cscript "'+WScript.ScriptFullName+'" "'+pathDest+'\\'+ファイルリスト[j]+'"', 1, true) | |
} | |
} | |
} | |
</script> | |
</job> |
「ライブラリの検索」ボックスに「.」と入力すると内容物が以下のように表示されるフォルダを上記スクリプトファイルにD&Dすると

こんな感じになります。

「/hoge/」のところを「/hoge/g」にすれば「hoge - コピー - hoge」とかいう名前は「fuga - コピー - fuga」になるようになります。
0 件のコメント:
コメントを投稿