// 指定したディレクトリの、指定した条件にマッチしたファイル名を、任意の文字列で挟み込んで
// テキストに書き出します。
// ワイルドカードは"*"(任意の文字列)、"?"(任意の1文字)が使えます。
// サブディレクトリのファイルも含めるには"dir /s /b"とします(その場合ファイル名はフルパスになる)。
// セパレータの"//"は" // "としても同じですが、文字列(1)//文字列(2)の前後の{space}=スペースは
// そのまま反映されるのでご注意ください。
// 拡張子は大文字小文字を区別しません。
// 例1) D:\Webpage\image // *.png; *.jpg //
|
// -> {space} |
// ※文字列(1)の末尾2文字が"/ "または"\ "のときに限り、末尾1文字の{space}は無視します。
//
// 例2) D:\Webpage\image//*.png;*.jpg//uploadFile -u -P -f // -d ./image -tF
// -> uploadFile -u -P -f hoge.png -d ./temp -tF
public cu_dir,f_type,msg
//OPTION DEFAULTFONT="Osaka−等幅"
TMPDIR="C:\Temp"
While True
wks=input("対象ファイルのディレクトリパス//ファイル名.拡張子//文字列(1)//文字列(2)を入力してください。 <#cr>"+_
"ファイル名.拡張子(条件)はセミコロン区切りで複数記入okです。拡張子を問わない場合は *.* とします。<#cr>"+_
"改行を含める場合は \\n を挿入してください。<#cr><#cr>"+_
"e.g) D:\Webpage\image//*.png;*.jpg//\\n./image///<#dbl>> | \\n
")
if wks=EMPTY then Exit
if pos("///",wks)>1 then wks=Chgmoj(wks,"///","/ //")
cu_dir=Copy(wks,1,val(pos("//",wks,1))-1)
if pos(" ",cu_dir,-1)=length(cu_dir) then cu_dir=Copy(cu_dir,1,val(length(cu_dir))-1)
f_type=Copy(wks,val(pos("//",wks,1))+2,val(pos("//",wks,2))-(val(pos("//",wks,1))+2))
if pos(" ",f_type)>=1 then f_type=Chgmoj(f_type," ","")
command_1=Copy(wks,val(pos("//",wks,2))+2,val(pos("//",wks,3))-(val(pos("//",wks,2))+2))
if (pos("/ ",command_1,-1)=val(length(command_1))-1) or (pos("\ ",command_1,-1)=val(length(command_1))-1)_
then command_1=Copy(command_1,1,val(length(command_1))-1)
command_2=Copy(wks,val(pos("//",wks,3))+2,(val(length(wks))+1)-(val(pos("//",wks,3))+2))
ifb find()
ifb MsgBox(msg,BTN_ABORT or BTN_RETRY,G_MOUSE_X-180,G_MOUSE_Y-90,BTN_RETRY)=BTN_RETRY
Continue
else
Exit
endif
endif
btn=MsgBox("※確認<#cr>書式がこれで良ければOKしてください<#cr>検索ディレクトリ: "+cu_dir+_
"<#cr>コマンドライン: "+command_1+f_type+command_2_
,BTN_OK or BTN_ABORT or BTN_RETRY,G_MOUSE_X-180,G_MOUSE_Y-90,BTN_OK)
ifb btn=BTN_OK
break
elseif btn=BTN_RETRY
Continue
else
Exit
endif
Sleep(0.2)
Wend
f_list=TMPDIR+"\f_list.txt"
SendStr(0,"cd /d "+cu_dir+"<#cr>dir /b "+f_type+" >"+f_list+"<#cr>ECHO テキストが表示されるまで暫らくお待ちください。")
prompt=exec("cmd")
Sleep(0.2)
Sckey(prompt,Vk_Alt,Vk_Space,E,P)
Kbd(Vk_Alt,2)
Sleep(0.2)
openlist=Fopen(f_list,F_read or F_write)
lines=1
for i=0 to Fget(openlist,F_linecount)-1
Fput(openlist,command_1+Fget(openlist,lines)+command_2,lines)
lines=lines+1
next
Fclose(openlist)
Sleep(2)
ifb (pos("\\n",command_1)>1) or (pos("\\n",command_2)>1)
openlist=Fopen(f_list,F_read)
all_txt=Fget(openlist,F_alltext)
all_txt=Chgmoj(all_txt,"\\n","<#cr>")
Fclose(openlist)
cr_txt=Fopen(TMPDIR+"\f_list_cr.txt",F_write)
Fput(cr_txt,all_txt)
Fclose(cr_txt)
Sleep(2)
Doscmd("del "+f_list)
Doscmd("start "+TMPDIR+"\f_list_cr.txt")
else
Doscmd("start "+TMPDIR+"\f_list.txt")
endif
CtrlWin(prompt,Close)
MsgBox("done")
function find()
result=false
ifb Fopen(cu_dir+"\",F_Exists)=0
msg="指定したディレクトリが見つかりません。"
result=true
elseif pos(";",f_type)>1
ifb Getdir(cu_dir,Copy(f_type,1,val(pos(";",f_type,1))-1))=0
msg="複数の条件を記入した場合、少なくとも1つ目のファイルタイプは<#cr>"+_
"確実に存在する拡張子にしてください。"
result=true
endif
else
ifb Getdir(cu_dir,f_type)=0
msg="指定したファイルが見つかりません。"
result=true
endif
endif
fend