CheckFilename1(name.s,ParentDirectory.s="")

Share your advanced PureBasic knowledge/code with the community.
User avatar
gurj
Enthusiast
Enthusiast
Posts: 640
Joined: Thu Jan 22, 2009 3:48 am
Location: china
Contact:

CheckFilename1(name.s,ParentDirectory.s="")

Post by gurj »

Code: Select all

Global Dim nm.s(11)
nm(n)="/":n+1
nm(n)="\":n+1
nm(n)=":":n+1
nm(n)=~"\"":n+1
nm(n)="?":n+1
nm(n)="*":n+1
nm(n)="|":n+1
nm(n)="<":n+1
nm(n)=">":n+1
nm(n)=Chr(9):n+1
nm(n)=Chr(10):n+1
nm(n)=Chr(13)

Procedure.s  CheckFilename1(name.s,ParentDirectory.s="");("a.ini","c:\")
 ;TODO note:
 name=Trim(name,".")
 nameLen=Len(name)
 c=Len(ParentDirectory)+nameLen
 If c>258
  ;#MAX_PATH=260,but need 'c:\'+{255}=258
  d=c-258
  MessageRequester("","too long ! please cut "+d+" character")
  ProcedureReturn "";TODO no
 EndIf
 If nameLen
  ;-{for winxp,see pb help CheckFilename()
  If nameLen=3
   l3.s{3}=UCase(name)
   If l3="AUX" Or l3="CON" Or l3="PRN" Or l3="NUL"
    MessageRequester("","name cannot is '"+name+"'")
    ProcedureReturn "";TODO no
   EndIf
  ElseIf nameLen=4
   l3=UCase(Left(name,3)):r1.s{1}=Right(name,1)
   If (l3="COM" Or l3="LPT") And r1<":" And r1>"/";0-9
    MessageRequester("","name cannot is '"+name+"' [Case insensitive]")
    ProcedureReturn "";TODO no
   EndIf
  EndIf
  ;}
  For t=1 To nameLen
   s1.s{1}=Mid(name,t,1)
   For a=0 To 11
    If s1=nm(a)
     MessageRequester("","please not use '"+s1+"'")
     ProcedureReturn "";TODO no
    EndIf
   Next
  Next
 Else
  MessageRequester("","name is blank !")
  ProcedureReturn "";TODO no
 EndIf
 ProcedureReturn name;TODO ok only here
EndProcedure
Debug CheckFilename1("ddd")
Debug CheckFilename1("/ytt")
Debug CheckFilename1(".")
Debug CheckFilename1("aux")
Debug CheckFilename1("COM6")
Debug CheckFilename1("LPt0")
Debug CheckFilename1(Chr(9))
Debug CheckFilename1(Chr(10))
Debug CheckFilename1(Chr(13))
Debug CheckFilename(Chr(9))
Debug CheckFilename(Chr(10))
Debug CheckFilename(Chr(13))

; IDE Options = PureBasic 5.72 (Windows - x86)
; CursorPosition = 67
; FirstLine = 49
; Folding = --
; DPIAware
; DisableDebugger
my pb for chinese:
http://ataorj.ys168.com