Selaa lähdekoodia

Updated filesystem examples.

woollybah 6 vuotta sitten
vanhempi
commit
54a30b9fae

+ 2 - 0
filesystem.mod/doc/changedir.bmx

@@ -1,5 +1,7 @@
 ' changedir.bmx
 
+SuperStrict
+
 Print "CurrentDir()="+CurrentDir()
 
 ' change current folder to the parent folder

+ 19 - 0
filesystem.mod/doc/closedir.bmx

@@ -0,0 +1,19 @@
+'File System Example
+
+SuperStrict
+
+Local dir:Byte Ptr = ReadDir(BlitzMaxPath())
+
+If Not dir Then
+	RuntimeError "Cannot open folder"
+End If
+
+Local file:String
+Repeat
+	
+	file = NextFile(dir) ' Get the filenames in folder
+	Print file
+	
+Until Not file
+
+CloseDir(dir)

+ 11 - 0
filesystem.mod/doc/closefile.bmx

@@ -0,0 +1,11 @@
+SuperStrict
+
+Local in:TStream = OpenFile(BlitzMaxPath() + "\versions.txt")
+Local line:String
+
+While Not Eof(in)
+	line = ReadLine(in)
+	Print line
+Wend
+
+CloseFile(in) ' can also use CloseStream(in)

+ 11 - 0
filesystem.mod/doc/closestream.bmx

@@ -0,0 +1,11 @@
+SuperStrict
+
+Local in:TStream = OpenFile(BlitzMaxPath() + "\versions.txt")
+Local line:String
+
+While Not Eof(in)
+	line = ReadLine(in)
+	Print line
+Wend
+
+CloseStream(in) ' can also use CloseFile(in)

+ 13 - 0
filesystem.mod/doc/copyfile.bmx

@@ -0,0 +1,13 @@
+SuperStrict
+
+Local result:Int = CopyFile(BlitzMaxPath() + "\versions.txt",  BlitzMaxPath() + "\versions2.txt")
+
+If result = 0 Then	
+	RuntimeError "CopyFile not successful..."
+End If
+
+result = RenameFile(BlitzMaxPath() + "\versions.txt", BlitzMaxPath() + "\versions2.txt")
+
+If result = 0 Then
+	RuntimeError "Rename not successful..." ' as file already exists
+End If

+ 3 - 1
filesystem.mod/doc/createdir.bmx

@@ -2,4 +2,6 @@
 SuperStrict
 
 Local success:Int = CreateDir("myfolder")
-If Not success RuntimeError "error creating directory"
+If Not success Then
+	RuntimeError "error creating directory"
+End If

+ 3 - 1
filesystem.mod/doc/createfile.bmx

@@ -2,4 +2,6 @@
 SuperStrict
 
 Local success:Int = CreateFile("myfile")
-If Not success RuntimeError "error creating file"
+If Not success Then
+	RuntimeError "error creating file"
+End If

+ 4 - 1
filesystem.mod/doc/deletedir.bmx

@@ -1,4 +1,7 @@
 ' deletedir.bmx
 SuperStrict
+
 Local success:Int = DeleteDir("myfolder")
-If Not success RuntimeError "error deleting directory"
+If Not success Then
+	RuntimeError "error deleting directory"
+End If

+ 3 - 1
filesystem.mod/doc/extractdir.bmx

@@ -1,3 +1,5 @@
 ' extractdir.bmx
 
-Print ExtractDir("mypath/myfile.bmx")	'prints mypath
+SuperStrict
+
+Print ExtractDir("mypath/myfile.bmx")	' prints mypath

+ 3 - 1
filesystem.mod/doc/extractext.bmx

@@ -1,3 +1,5 @@
 ' extractext.bmx
 
-Print ExtractExt("mypath/myfile.bmx")	'prints bmx
+SuperStrict
+
+Print ExtractExt("mypath/myfile.bmx")	' prints bmx

+ 2 - 0
filesystem.mod/doc/filesize.bmx

@@ -1,5 +1,7 @@
 ' filesize.bmx
 
+SuperStrict
+
 ' the following prints the size of this source file in bytes
 
 Print FileSize("filesize.bmx")

+ 2 - 0
filesystem.mod/doc/filetime.bmx

@@ -1,3 +1,5 @@
 ' filetime.bmx
 
+SuperStrict
+
 Print FileTime("filetime.bmx")

+ 5 - 3
filesystem.mod/doc/filetype.bmx

@@ -1,5 +1,7 @@
 ' filetype.bmx
 
-Print FileType(".")		'prints 2 for directory type
-Print FileType("filetype.bmx")	'prints 1 for file type
-Print FileType("notfound.file")	'prints 0 for doesn't exist
+SuperStrict
+
+Print FileType(".")		' prints 2 for directory type
+Print FileType("filetype.bmx")	' prints 1 for file type
+Print FileType("notfound.file")	' prints 0 for doesn't exist

+ 19 - 0
filesystem.mod/doc/nextfile.bmx

@@ -0,0 +1,19 @@
+'File System Example
+
+SuperStrict
+
+Local dir:Byte Ptr = ReadDir(BlitzMaxPath() )
+
+If Not dir Then
+	RuntimeError "Cannot open folder"
+End If
+
+Local file:String
+Repeat
+	
+	file = NextFile(Dir) ' Get the filenames in folder
+	Print file
+	
+Until file = ""
+
+CloseDir(dir)

+ 2 - 0
filesystem.mod/doc/realpath.bmx

@@ -1,5 +1,7 @@
 ' realpath.bmx
 
+SuperStrict
+
 Print RealPath("realpath.bmx")	'prints full path of this source
 
 Print RealPath("..") 'prints full path of parent directory

+ 13 - 0
filesystem.mod/doc/renamefile.bmx

@@ -0,0 +1,13 @@
+SuperStrict
+
+Local result:Int = CopyFile(BlitzMaxPath() + "\versions.txt", BlitzMaxPath() + "\versions2.txt")
+
+If result = 0 Then
+	RuntimeError "CopyFile not successful..."
+End If
+
+result = RenameFile(BlitzMaxPath() + "\versions.txt", BlitzMaxPath() + "\versions2.txt")
+
+If result = 0 Then
+	RuntimeError "Rename not successful..." ' as file already exist
+End If

+ 3 - 1
filesystem.mod/doc/stripall.bmx

@@ -1,3 +1,5 @@
 ' stripall.bmx
 
-Print StripAll("mypath/myfile.bmx")	'prints myfile
+SuperStrict
+
+Print StripAll("mypath/myfile.bmx")	' prints myfile

+ 3 - 1
filesystem.mod/doc/stripdir.bmx

@@ -1,3 +1,5 @@
 ' stripdir.bmx
 
-Print StripDir("mypath/myfile.bmx")	'prints myfile.bmx
+SuperStrict
+
+Print StripDir("mypath/myfile.bmx")	' prints myfile.bmx

+ 3 - 1
filesystem.mod/doc/stripext.bmx

@@ -1,3 +1,5 @@
 ' stripext.bmx
 
-Print StripExt("mypath/myfile.bmx")	'prints mypath/myfile
+SuperStrict
+
+Print StripExt("mypath/myfile.bmx")	' prints mypath/myfile

+ 1 - 1
filesystem.mod/doc/stripslash.bmx

@@ -1,4 +1,4 @@
 ' stripslash.bmx
 SuperStrict
 
-Print StripSlash("mypath/")	'prints mypath
+Print StripSlash("mypath/")	' prints mypath