ファイル名もしくはディレクトリ名として使える名前かチェックするモジュールです。
ファイル名もしくはディレクトリ名として使える名前かチェックするモジュールです。
#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 _buftextbuftext = _buftextsdim u_text, strlen(buftext)*2+2cnvstow u_text, buftextr = 0repeatif wpeek(u_text, cnt*2) == 0 : breakPathGetCharTypeW wpeek(u_text, cnt*2)if stat == 0 | stat == 4 | stat == 8 : r = -1 : breakloopreturn r#defcfunc IsDirNamePath str _buftextbuftext = _buftextsdim u_text, strlen(buftext)*2+2cnvstow u_text, buftextr = 0repeatif wpeek(u_text, cnt*2) == 0 : breakPathGetCharTypeW wpeek(u_text, cnt*2)if stat == 0 | stat == 4 : r = -1 : breakloopreturn r#global// 使えない文字だと -1 が返りますmes IsFileNamePath("text.txt") ; 問題ないファイル名なのでOKmes IsDirNamePath("C:\\test.txt") ; 問題ないディレクトリ名なのでOKmes IsFileNamePath("C:\\test.txt") ; ファイル名としては\は使えないのでNGmes IsDirNamePath("C:\\test.txt") ; ディレクトリ名ならOKmes IsFileNamePath("test?.txt") ; ?は使えないのでNGmes IsDirNamePath("C:\\test?.txt") ; ?は使えないのでNG