forked from Ixiko/AHK-libs-and-classes-collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIsValidFileName.ahk
48 lines (39 loc) · 1.18 KB
/
IsValidFileName.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
Author: Tuncay
License: http://creativecommons.org/licenses/by/3.0/
Func: isValidFileName
Test if a string is a valid file name.
Parameters:
fileName - Input string to test if it contains any character from
list of forbidden characters.
isLong - If true (default) then fileName is treated as long file name.
Otherwise it is handled as a short 8.3 filename type.
Returns:
True if valid and false otherwise.
ErrorLevel:
The position of first invalid character in filename. '0' if filename is
valid.
Remarks:
* Naming Files, Paths, and Namespaces:
<http://msdn.microsoft.com/en-us/library/Aa365247>
Example:
> MsgBox % isValidFileName(A_ScriptName)
*Output*
1
*/
isValidFileName(_fileName, _isLong=true)
{
static shortForbiddenChars := ";,=,+,<,>,|,"",[,],\,/,'"
static longForbiddenChars := "<,>,|,"",\,/,:,*,?"
forbiddenChars := _isLong ? longForbiddenChars : shortForbiddenChars
Loop, Parse, forbiddenChars, `,
{
pos := InStr(_fileName, A_LoopField, true)
if (pos > 0)
{
break
}
}
ErrorLevel := pos
return (pos ? false : true)
}