PureBasic Forum
http://forums.purebasic.com/english/

CheckFilename1(name.s,ParentDirectory.s="")
http://forums.purebasic.com/english/viewtopic.php?f=12&t=75133
Page 1 of 1

Author:  gurj [ Mon Apr 20, 2020 3:49 pm ]
Post subject:  CheckFilename1(name.s,ParentDirectory.s="")

Code:
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

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/