ファイル名もしくはディレクトリ名として使える名前かチェックするモジュールです。
ファイル名もしくはディレクトリ名として使える名前かチェックするモジュールです。
#module _FileNameCheck_
#uselib "Shlwapi.dll"
#func PathGetCharTypeA "PathGetCharTypeA" int
#func PathGetCharTypeW "PathGetCharTypeW" int
#define GCT_INVALID 0 // この文字はパスに使用できない。
#define GCT_LFNCHAR 1 // この文字は長い形式のファイル名に使用することができる。
#define GCT_SHORTCHAR 2 // この文字は短い形式のファイル名に使用することができる。
#define GCT_WILD 4 // この文字はワイルドカード文字である。
#define GCT_SEPARATOR 8 // この文字はパスの区切りの文字である。
#defcfunc IsFileNamePath str _buftext
buftext = _buftext
sdim u_text, strlen(buftext)*2+2
cnvstow u_text, buftext
r = 0
repeat
if wpeek(u_text, cnt*2) == 0 : break
PathGetCharTypeW wpeek(u_text, cnt*2)
if stat == 0 | stat == 4 | stat == 8 : r = -1 : break
loop
return r
#defcfunc IsDirNamePath str _buftext
buftext = _buftext
sdim u_text, strlen(buftext)*2+2
cnvstow u_text, buftext
r = 0
repeat
if wpeek(u_text, cnt*2) == 0 : break
PathGetCharTypeW wpeek(u_text, cnt*2)
if stat == 0 | stat == 4 : r = -1 : break
loop
return r
#global
// 使えない文字だと -1 が返ります
mes IsFileNamePath("text.txt") ; 問題ないファイル名なのでOK
mes IsDirNamePath("C:\\test.txt") ; 問題ないディレクトリ名なのでOK
mes IsFileNamePath("C:\\test.txt") ; ファイル名としては\は使えないのでNG
mes IsDirNamePath("C:\\test.txt") ; ディレクトリ名ならOK
mes IsFileNamePath("test?.txt") ; ?は使えないのでNG
mes IsDirNamePath("C:\\test?.txt") ; ?は使えないのでNG