Skip to content

Instantly share code, notes, and snippets.

@nonkit
Last active April 1, 2020 07:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonkit/f5701dc5342d2bf8620102ffabc7ae65 to your computer and use it in GitHub Desktop.
Save nonkit/f5701dc5342d2bf8620102ffabc7ae65 to your computer and use it in GitHub Desktop.
Small Basic Pseudo File Object
Sub File_CheckResult
' File | check File operation result
' param result, dirs or files - result of a File operation
' param op - name of File operation
If (op = "GetDirectories") And (dirs = "FAILED") Then
FileHelper_ShowError()
ElseIf (op = "GetFiles") And (files = "FAILED") Then
FileHelper_ShowError()
ElseIf result = "FAILED" Then
FileHelper_ShowError()
EndIf
EndSub
Sub File_Exists
' File | check a file exists
' param["path"] - the full path of the file that needs to be checked
' return fileExists - "True" if the file exists
fileExists = "False"
File_SplitDirectory()
files = File.GetFiles(directoryName)
op = "GetFiles"
File_CheckResult()
nFiles = Array.GetItemCount(files)
For i = 1 To nFiles
If Text.ConvertToLowerCase(files[i]) = Text.ConvertToLowerCase(param["path"]) Then
fileExists = "True"
i = nFiles ' exit For
EndIf
EndFor
EndSub
Sub File_SplitDirectory
' File | split directory name
' param["path"] - the full path to be gotton directory name
' return directoryName - the directory name
directoryName = ""
For p = Text.GetLength(param["path"]) To 1 Step -1
c = Text.GetSubText(param["path"], p, 1)
If c = "\" Or c = "/" Then
directoryName = Text.GetSubText(param["path"], 1, p - 1)
p = 1 ' exit For
EndIf
EndFor
EndSub
Sub FileHelper_ShowError
' File Helper | show last errer
' param op - oparation name
' param indent - indent space if needed
TextWindow.ForegroundColor = "Yellow"
TextWindow.WriteLine(indent + op + ":FAILED")
TextWindow.WriteLine(indent + "LastError:" + File.LastError)
TextWindow.ForegroundColor = "Gray"
EndSub
@nonkit
Copy link
Author

nonkit commented May 31, 2019

Please push [Raw] button before copy and paste these snippets to your program.

@nonkit
Copy link
Author

nonkit commented May 31, 2019

Variables op, dirs, files and indent should be initialized before using File_CheckResult subroutine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment