|
@@ -1,17 +1,19 @@
|
|
|
|
|
|
-Strict
|
|
|
|
|
|
+SuperStrict
|
|
|
|
|
|
Rem
|
|
Rem
|
|
bbdoc: System/File system
|
|
bbdoc: System/File system
|
|
End Rem
|
|
End Rem
|
|
Module BRL.FileSystem
|
|
Module BRL.FileSystem
|
|
|
|
|
|
-ModuleInfo "Version: 1.09"
|
|
|
|
|
|
+ModuleInfo "Version: 1.10"
|
|
ModuleInfo "Author: Mark Sibly"
|
|
ModuleInfo "Author: Mark Sibly"
|
|
ModuleInfo "License: zlib/libpng"
|
|
ModuleInfo "License: zlib/libpng"
|
|
ModuleInfo "Copyright: Blitz Research Ltd"
|
|
ModuleInfo "Copyright: Blitz Research Ltd"
|
|
ModuleInfo "Modserver: BRL"
|
|
ModuleInfo "Modserver: BRL"
|
|
|
|
|
|
|
|
+ModuleInfo "History: 1.10"
|
|
|
|
+ModuleInfo "History: Module is now SuperStrict"
|
|
ModuleInfo "History: 1.09 Release"
|
|
ModuleInfo "History: 1.09 Release"
|
|
ModuleInfo "History: Fixed RealPath breaking win32 //server paths"
|
|
ModuleInfo "History: Fixed RealPath breaking win32 //server paths"
|
|
ModuleInfo "History: 1.08 Release"
|
|
ModuleInfo "History: 1.08 Release"
|
|
@@ -28,7 +30,7 @@ ModuleInfo "History: Added optional resurse parameter to CreateDir"
|
|
Import Pub.StdC
|
|
Import Pub.StdC
|
|
Import BRL.BankStream
|
|
Import BRL.BankStream
|
|
|
|
|
|
-Const FILETYPE_NONE=0,FILETYPE_FILE=1,FILETYPE_DIR=2
|
|
|
|
|
|
+Const FILETYPE_NONE:Int=0,FILETYPE_FILE:Int=1,FILETYPE_DIR:Int=2
|
|
|
|
|
|
Private
|
|
Private
|
|
|
|
|
|
@@ -37,39 +39,39 @@ Function _RootPath$( path$ )
|
|
If path.StartsWith( "//" )
|
|
If path.StartsWith( "//" )
|
|
Return path[ ..path.Find( "/",2 )+1 ]
|
|
Return path[ ..path.Find( "/",2 )+1 ]
|
|
EndIf
|
|
EndIf
|
|
- Local i=path.Find( ":" )
|
|
|
|
|
|
+ Local i:Int=path.Find( ":" )
|
|
If i<>-1 And path.Find( "/" )=i+1 Return path[..i+2]
|
|
If i<>-1 And path.Find( "/" )=i+1 Return path[..i+2]
|
|
?
|
|
?
|
|
If path.StartsWith( "/" ) Return "/"
|
|
If path.StartsWith( "/" ) Return "/"
|
|
End Function
|
|
End Function
|
|
|
|
|
|
-Function _IsRootPath( path$ )
|
|
|
|
|
|
+Function _IsRootPath:Int( path$ )
|
|
Return path And _RootPath( path )=path
|
|
Return path And _RootPath( path )=path
|
|
End Function
|
|
End Function
|
|
|
|
|
|
-Function _IsRealPath( path$ )
|
|
|
|
|
|
+Function _IsRealPath:Int( path$ )
|
|
Return _RootPath( path )<>""
|
|
Return _RootPath( path )<>""
|
|
End Function
|
|
End Function
|
|
|
|
|
|
?Win32
|
|
?Win32
|
|
Function _CurrentDrive$()
|
|
Function _CurrentDrive$()
|
|
Local cd$=getcwd_()
|
|
Local cd$=getcwd_()
|
|
- Local i=cd.Find( ":" )
|
|
|
|
|
|
+ Local i:Int=cd.Find( ":" )
|
|
If i<>-1 Return cd[..i]
|
|
If i<>-1 Return cd[..i]
|
|
End Function
|
|
End Function
|
|
?
|
|
?
|
|
|
|
|
|
Public
|
|
Public
|
|
|
|
|
|
-Function FixPath( path$ Var,dirPath=False )
|
|
|
|
|
|
+Function FixPath( path$ Var,dirPath:Int=False )
|
|
path=path.Replace("\","/")
|
|
path=path.Replace("\","/")
|
|
?Win32
|
|
?Win32
|
|
If path.StartsWith( "//" )
|
|
If path.StartsWith( "//" )
|
|
If path.Find( "/",2 )=-1 path:+"/"
|
|
If path.Find( "/",2 )=-1 path:+"/"
|
|
Else
|
|
Else
|
|
- Local i=path.Find( ":" )
|
|
|
|
|
|
+ Local i:Int=path.Find( ":" )
|
|
If i<>-1 And ( i=path.length-1 Or path[i+1]<>Asc(":") )
|
|
If i<>-1 And ( i=path.length-1 Or path[i+1]<>Asc(":") )
|
|
- Local i2=path.Find( "/" )
|
|
|
|
|
|
+ Local i2:Int=path.Find( "/" )
|
|
If i2=-1 Or i2>i+1 path=path[..i+1]+"/"+path[i+1..]
|
|
If i2=-1 Or i2>i+1 path=path[..i+1]+"/"+path[i+1..]
|
|
EndIf
|
|
EndIf
|
|
EndIf
|
|
EndIf
|
|
@@ -85,7 +87,7 @@ bbdoc: Strip directory from a file path
|
|
End Rem
|
|
End Rem
|
|
Function StripDir$( path$ )
|
|
Function StripDir$( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local i=path.FindLast( "/" )
|
|
|
|
|
|
+ Local i:Int=path.FindLast( "/" )
|
|
If i<>-1 Return path[i+1..]
|
|
If i<>-1 Return path[i+1..]
|
|
Return path
|
|
Return path
|
|
End Function
|
|
End Function
|
|
@@ -95,7 +97,7 @@ bbdoc: Strip extension from a file path
|
|
End Rem
|
|
End Rem
|
|
Function StripExt$( path$ )
|
|
Function StripExt$( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local i=path.FindLast( "." )
|
|
|
|
|
|
+ Local i:Int=path.FindLast( "." )
|
|
If i<>-1 And path.Find( "/",i+1 )=-1 Return path[..i]
|
|
If i<>-1 And path.Find( "/",i+1 )=-1 Return path[..i]
|
|
Return path
|
|
Return path
|
|
End Function
|
|
End Function
|
|
@@ -126,7 +128,7 @@ Function ExtractDir$( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
If path="." Or path=".." Or _IsRootPath( path ) Return path
|
|
If path="." Or path=".." Or _IsRootPath( path ) Return path
|
|
|
|
|
|
- Local i=path.FindLast( "/" )
|
|
|
|
|
|
+ Local i:Int=path.FindLast( "/" )
|
|
If i=-1 Return ""
|
|
If i=-1 Return ""
|
|
|
|
|
|
If _IsRootPath( path[..i+1] ) i:+1
|
|
If _IsRootPath( path[..i+1] ) i:+1
|
|
@@ -138,7 +140,7 @@ bbdoc: Extract extension from a file path
|
|
End Rem
|
|
End Rem
|
|
Function ExtractExt$( path$ )
|
|
Function ExtractExt$( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local i=path.FindLast( "." )
|
|
|
|
|
|
+ Local i:Int=path.FindLast( "." )
|
|
If i<>-1 And path.Find( "/",i+1 )=-1 Return path[i+1..]
|
|
If i<>-1 And path.Find( "/",i+1 )=-1 Return path[i+1..]
|
|
End Function
|
|
End Function
|
|
|
|
|
|
@@ -172,7 +174,7 @@ Function RealPath$( path$ )
|
|
|
|
|
|
path:+"/"
|
|
path:+"/"
|
|
While path
|
|
While path
|
|
- Local i=path.Find( "/" )
|
|
|
|
|
|
+ Local i:Int=path.Find( "/" )
|
|
Local t$=path[..i]
|
|
Local t$=path[..i]
|
|
path=path[i+1..]
|
|
path=path[i+1..]
|
|
Select t
|
|
Select t
|
|
@@ -193,9 +195,9 @@ Rem
|
|
bbdoc: Get file type
|
|
bbdoc: Get file type
|
|
returns: 0 if file at @path doesn't exist, FILETYPE_FILE (1) if the file is a plain file or FILETYPE_DIR (2) if the file is a directory
|
|
returns: 0 if file at @path doesn't exist, FILETYPE_FILE (1) if the file is a plain file or FILETYPE_DIR (2) if the file is a directory
|
|
End Rem
|
|
End Rem
|
|
-Function FileType( path$ )
|
|
|
|
|
|
+Function FileType:Int( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local Mode,size:Long,mtime,ctime
|
|
|
|
|
|
+ Local Mode:Int,size:Long,mtime:Int,ctime:Int
|
|
If stat_( path,Mode,size,mtime,ctime ) Return 0
|
|
If stat_( path,Mode,size,mtime,ctime ) Return 0
|
|
Select Mode & S_IFMT_
|
|
Select Mode & S_IFMT_
|
|
Case S_IFREG_ Return FILETYPE_FILE
|
|
Case S_IFREG_ Return FILETYPE_FILE
|
|
@@ -208,9 +210,9 @@ Rem
|
|
bbdoc: Get file time
|
|
bbdoc: Get file time
|
|
returns: The time the file at @path was last modified
|
|
returns: The time the file at @path was last modified
|
|
End Rem
|
|
End Rem
|
|
-Function FileTime( path$ )
|
|
|
|
|
|
+Function FileTime:Int( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local Mode,size:Long,mtime,ctime
|
|
|
|
|
|
+ Local Mode:Int,size:Long,mtime:Int,ctime:Int
|
|
If stat_( path,Mode,size,mtime,ctime ) Return 0
|
|
If stat_( path,Mode,size,mtime,ctime ) Return 0
|
|
Return mtime
|
|
Return mtime
|
|
End Function
|
|
End Function
|
|
@@ -221,7 +223,7 @@ returns: Size, in bytes, of the file at @path, or -1 if the file does not exist
|
|
end rem
|
|
end rem
|
|
Function FileSize:Long( path$ )
|
|
Function FileSize:Long( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local Mode,size:Long,mtime,ctime
|
|
|
|
|
|
+ Local Mode:Int,size:Long,mtime:Int,ctime:Int
|
|
If stat_( path,Mode,size,mtime,ctime ) Return -1
|
|
If stat_( path,Mode,size,mtime,ctime ) Return -1
|
|
Return size
|
|
Return size
|
|
End Function
|
|
End Function
|
|
@@ -230,9 +232,9 @@ Rem
|
|
bbdoc: Get file mode
|
|
bbdoc: Get file mode
|
|
returns: file mode flags
|
|
returns: file mode flags
|
|
end rem
|
|
end rem
|
|
-Function FileMode( path$ )
|
|
|
|
|
|
+Function FileMode:Int( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
- Local Mode,size:Long,mtime,ctime
|
|
|
|
|
|
+ Local Mode:Int,size:Long,mtime:Int,ctime:Int
|
|
If stat_( path,Mode,size,mtime,ctime ) Return -1
|
|
If stat_( path,Mode,size,mtime,ctime ) Return -1
|
|
Return Mode & 511
|
|
Return Mode & 511
|
|
End Function
|
|
End Function
|
|
@@ -240,7 +242,7 @@ End Function
|
|
Rem
|
|
Rem
|
|
bbdoc: Set file mode
|
|
bbdoc: Set file mode
|
|
end rem
|
|
end rem
|
|
-Function SetFileMode( path$,Mode )
|
|
|
|
|
|
+Function SetFileMode( path$,Mode:Int )
|
|
FixPath path
|
|
FixPath path
|
|
chmod_ path,Mode
|
|
chmod_ path,Mode
|
|
End Function
|
|
End Function
|
|
@@ -249,7 +251,7 @@ Rem
|
|
bbdoc: Create a file
|
|
bbdoc: Create a file
|
|
returns: True if successful
|
|
returns: True if successful
|
|
End Rem
|
|
End Rem
|
|
-Function CreateFile( path$ )
|
|
|
|
|
|
+Function CreateFile:Int( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
remove_ path
|
|
remove_ path
|
|
Local t:Byte Ptr=fopen_( path,"wb" )
|
|
Local t:Byte Ptr=fopen_( path,"wb" )
|
|
@@ -263,7 +265,7 @@ returns: True if successful
|
|
about:
|
|
about:
|
|
If @recurse is true, any required subdirectories are also created.
|
|
If @recurse is true, any required subdirectories are also created.
|
|
End Rem
|
|
End Rem
|
|
-Function CreateDir( path$,recurse=False )
|
|
|
|
|
|
+Function CreateDir:Int( path$,recurse:Int=False )
|
|
FixPath path,True
|
|
FixPath path,True
|
|
If Not recurse
|
|
If Not recurse
|
|
mkdir_ path,1023
|
|
mkdir_ path,1023
|
|
@@ -272,7 +274,7 @@ Function CreateDir( path$,recurse=False )
|
|
Local t$
|
|
Local t$
|
|
path=RealPath(path)+"/"
|
|
path=RealPath(path)+"/"
|
|
While path
|
|
While path
|
|
- Local i=path.find("/")+1
|
|
|
|
|
|
+ Local i:Int=path.find("/")+1
|
|
t:+path[..i]
|
|
t:+path[..i]
|
|
path=path[i..]
|
|
path=path[i..]
|
|
Select FileType(t)
|
|
Select FileType(t)
|
|
@@ -292,7 +294,7 @@ Rem
|
|
bbdoc: Delete a file
|
|
bbdoc: Delete a file
|
|
returns: True if successful
|
|
returns: True if successful
|
|
End Rem
|
|
End Rem
|
|
-Function DeleteFile( path$ )
|
|
|
|
|
|
+Function DeleteFile:Int( path$ )
|
|
FixPath path
|
|
FixPath path
|
|
remove_ path
|
|
remove_ path
|
|
Return FileType(path)=FILETYPE_NONE
|
|
Return FileType(path)=FILETYPE_NONE
|
|
@@ -302,7 +304,7 @@ Rem
|
|
bbdoc: Renames a file
|
|
bbdoc: Renames a file
|
|
returns: True if successful
|
|
returns: True if successful
|
|
End Rem
|
|
End Rem
|
|
-Function RenameFile( oldpath$,newpath$ )
|
|
|
|
|
|
+Function RenameFile:Int( oldpath$,newpath$ )
|
|
FixPath oldpath
|
|
FixPath oldpath
|
|
FixPath newpath
|
|
FixPath newpath
|
|
Return rename_( oldpath,newpath)=0
|
|
Return rename_( oldpath,newpath)=0
|
|
@@ -312,8 +314,8 @@ Rem
|
|
bbdoc: Copy a file
|
|
bbdoc: Copy a file
|
|
returns: True if successful
|
|
returns: True if successful
|
|
End Rem
|
|
End Rem
|
|
-Function CopyFile( src$,dst$ )
|
|
|
|
- Local in:TStream=ReadStream( src ),ok
|
|
|
|
|
|
+Function CopyFile:Int( src$,dst$ )
|
|
|
|
+ Local in:TStream=ReadStream( src ),ok:Int
|
|
If in
|
|
If in
|
|
Local out:TStream=WriteStream( dst )
|
|
Local out:TStream=WriteStream( dst )
|
|
If out
|
|
If out
|
|
@@ -333,9 +335,9 @@ Rem
|
|
bbdoc: Copy a directory
|
|
bbdoc: Copy a directory
|
|
returns: True if successful
|
|
returns: True if successful
|
|
End Rem
|
|
End Rem
|
|
-Function CopyDir( src$,dst$ )
|
|
|
|
|
|
+Function CopyDir:Int( src$,dst$ )
|
|
|
|
|
|
- Function CopyDir_( src$,dst$ )
|
|
|
|
|
|
+ Function CopyDir_:Int( src$,dst$ )
|
|
If FileType( dst )=FILETYPE_NONE CreateDir dst
|
|
If FileType( dst )=FILETYPE_NONE CreateDir dst
|
|
If FileType( dst )<>FILETYPE_DIR Return False
|
|
If FileType( dst )<>FILETYPE_DIR Return False
|
|
For Local file$=EachIn LoadDir( src )
|
|
For Local file$=EachIn LoadDir( src )
|
|
@@ -364,11 +366,11 @@ returns: True if successful
|
|
about: Set @recurse to true to delete all subdirectories and files recursively -
|
|
about: Set @recurse to true to delete all subdirectories and files recursively -
|
|
but be careful!
|
|
but be careful!
|
|
End Rem
|
|
End Rem
|
|
-Function DeleteDir( path$,recurse=False )
|
|
|
|
|
|
+Function DeleteDir:Int( path$,recurse:Int=False )
|
|
FixPath path,True
|
|
FixPath path,True
|
|
If recurse
|
|
If recurse
|
|
Local dir:Byte Ptr=ReadDir( path )
|
|
Local dir:Byte Ptr=ReadDir( path )
|
|
- If Not dir Return
|
|
|
|
|
|
+ If Not dir Return False
|
|
Repeat
|
|
Repeat
|
|
Local t$=NextFile( dir )
|
|
Local t$=NextFile( dir )
|
|
If t="" Exit
|
|
If t="" Exit
|
|
@@ -389,7 +391,7 @@ Rem
|
|
bbdoc: Change current directory
|
|
bbdoc: Change current directory
|
|
returns: True if successful
|
|
returns: True if successful
|
|
End Rem
|
|
End Rem
|
|
-Function ChangeDir( path$ )
|
|
|
|
|
|
+Function ChangeDir:Int( path$ )
|
|
FixPath path,True
|
|
FixPath path,True
|
|
If chdir_( path )=0 Return True
|
|
If chdir_( path )=0 Return True
|
|
End Function
|
|
End Function
|
|
@@ -424,11 +426,11 @@ returns: A string array containing contents of @dir
|
|
about: The @skip_dots parameter, if true, removes the '.' (current) and '..'
|
|
about: The @skip_dots parameter, if true, removes the '.' (current) and '..'
|
|
(parent) directories from the returned array.
|
|
(parent) directories from the returned array.
|
|
end rem
|
|
end rem
|
|
-Function LoadDir$[]( dir$,skip_dots=True )
|
|
|
|
|
|
+Function LoadDir$[]( dir$,skip_dots:Int=True )
|
|
FixPath dir,True
|
|
FixPath dir,True
|
|
Local d:Byte Ptr=ReadDir( dir )
|
|
Local d:Byte Ptr=ReadDir( dir )
|
|
- If Not d Return
|
|
|
|
- Local i$[100],n
|
|
|
|
|
|
+ If Not d Return Null
|
|
|
|
+ Local i$[100],n:Int
|
|
Repeat
|
|
Repeat
|
|
Local f$=NextFile( d )
|
|
Local f$=NextFile( d )
|
|
If Not f Exit
|
|
If Not f Exit
|
|
@@ -449,15 +451,15 @@ to cache the contents of the file to ensure serial streams such as
|
|
http: based url's are seekable. Use the #CloseStream command when
|
|
http: based url's are seekable. Use the #CloseStream command when
|
|
finished reading and or writing to a Stream returned by #OpenFile.
|
|
finished reading and or writing to a Stream returned by #OpenFile.
|
|
End Rem
|
|
End Rem
|
|
-Function OpenFile:TStream( url:Object,readable=True,writeable=True )
|
|
|
|
|
|
+Function OpenFile:TStream( url:Object,readable:Int=True,writeable:Int=True )
|
|
Local stream:TStream=OpenStream( url,readable,writeable )
|
|
Local stream:TStream=OpenStream( url,readable,writeable )
|
|
- If Not stream Return
|
|
|
|
|
|
+ If Not stream Return Null
|
|
If stream.Pos()=-1 Return TBankStream.Create( TBank.Load(stream) )
|
|
If stream.Pos()=-1 Return TBankStream.Create( TBank.Load(stream) )
|
|
Return stream
|
|
Return stream
|
|
End Function
|
|
End Function
|
|
|
|
|
|
Rem
|
|
Rem
|
|
-bbdoc: Open a file for input.
|
|
|
|
|
|
+bbdoc: Open a file For Input.
|
|
about:
|
|
about:
|
|
This command is similar to the #ReadStream command but will attempt
|
|
This command is similar to the #ReadStream command but will attempt
|
|
to cache the contents of the file to ensure serial streams such as
|
|
to cache the contents of the file to ensure serial streams such as
|