Utilities for reading and writing files on various platforms.
Static variables
staticfinalread onlyFILE_EXTENSION_INFO_FNFC:FileDialogExtensionInfo = { extension : "fnfc", label : "Friday Night Funkin' Chart" }
staticfinalread onlyFILE_EXTENSION_INFO_FNFS:FileDialogExtensionInfo = { extension : "fnfs", label : "Friday Night Funkin' Stage" }
staticfinalread onlyFILE_EXTENSION_INFO_PNG:FileDialogExtensionInfo = { extension : "png", label : "PNG Image" }
staticfinalread onlyFILE_EXTENSION_INFO_ZIP:FileDialogExtensionInfo = { extension : "zip", label : "ZIP Archive" }
staticfinalread onlyFILE_FILTER_FNFC:FileFilter = new FileFilter("Friday Night Funkin' Chart (.fnfc)", "*.fnfc")
staticfinalread onlyFILE_FILTER_FNFS:FileFilter = new FileFilter("Friday Night Funkin' Stage (.fnfs)", "*.fnfs")
staticfinalread onlyFILE_FILTER_JSON:FileFilter = new FileFilter("JSON Data File (.json)", "*.json")
staticread onlyPROTECTED_PATHS:Array<String>
Paths which should not be deleted or modified by scripts.
Static methods
staticappendStringToPath(path:String, data:String):Void
Write string file contents directly to the end of a file at the given path. Only works on native.
Parameters:
path | The path to the file. |
|---|---|
data | The string to append. |
staticbrowseFileReference(callback:FileReference ‑> Void):Void
Browse for a file to read and execute a callback once we have a file reference. Works great on HTML5 or desktop.
Parameters:
callback | The function to call when the file is loaded. |
|---|
staticbrowseForBinaryFile(dialogTitle:String, ?typeFilter:Array<FileDialogExtensionInfo>, onSelect:SelectedFileInfo ‑> Void, ?onCancel:() ‑> Void):Void
Browses for a single file, then calls onSelect(fileInfo) when a file is selected.
Powered by HaxeUI, so it works on all platforms.
File contents will be binary, not String.
Parameters:
typeFilter | |
|---|---|
onSelect | A callback that provides a |
onCancel | A callback that is called when the user closes the dialog without selecting a file. |
staticbrowseForDirectory(?typeFilter:Array<FileFilter>, onSelect:String ‑> Void, ?onCancel:() ‑> Void, ?defaultPath:String, ?dialogTitle:String):Bool
Browses for a directory, then calls onSelect(path) when a path chosen.
Note that on HTML5 this will immediately fail.
Parameters:
typeFilter | TODO What does this do? |
|---|
Returns:
Whether the file dialog was opened successfully.
staticbrowseForMultipleFiles(?typeFilter:Array<FileFilter>, onSelect:Array<String> ‑> Void, ?onCancel:() ‑> Void, ?defaultPath:String, ?dialogTitle:String):Bool
Browses for multiple file, then calls onSelect(paths) when a path chosen.
Note that on HTML5 this will immediately fail.
Returns:
Whether the file dialog was opened successfully.
staticbrowseForSaveFile(?typeFilter:Array<FileFilter>, onSelect:String ‑> Void, ?onCancel:() ‑> Void, ?defaultPath:String, ?dialogTitle:String):Bool
Browses for a file location to save to, then calls onSave(path) when a path chosen.
Note that on HTML5 you can't do much with this, you should call saveFile(resource:haxe.io.Bytes) instead.
Parameters:
typeFilter | TODO What does this do? |
|---|
Returns:
Whether the file dialog was opened successfully.
staticbrowseForTextFile(dialogTitle:String, ?typeFilter:Array<FileDialogExtensionInfo>, onSelect:SelectedFileInfo ‑> Void, ?onCancel:() ‑> Void):Void
Browses for a single file, then calls onSelect(fileInfo) when a file is selected.
Powered by HaxeUI, so it works on all platforms.
File contents will be a String, not binary.
Parameters:
typeFilter | |
|---|---|
onSelect | A callback that provides a |
onCancel | A callback that is called when the user closes the dialog without selecting a file. |
staticcreateDirIfNotExists(dir:String):Void
Create a directory if it doesn't already exist. Only works on native.
Parameters:
dir | The path to the directory. |
|---|
staticcreateZIPFromEntries(entries:Array<Entry>):Bytes
Create a Bytes object containing a ZIP file, containing the provided entries.
Parameters:
entries | The entries to add to the ZIP file. |
|---|
Returns:
The ZIP file as a Bytes object.
staticdeleteDir(path:String, recursive:Bool = false, ?ignore:Array<String>):Void
Delete a directory, optionally including its contents, and optionally ignoring some paths. Only works on native.
Parameters:
path | The path to the directory. |
|---|---|
recursive | Whether to delete all contents of the directory. |
ignore | A list of paths to ignore. |
staticdeleteFile(path:String):Void
Delete a file at the given path. Only works on native.
Parameters:
path | The path to the file. |
|---|
staticdirectoryExists(path:String):Bool
Check if a path is a directory on the filesystem. Only works on native.
Parameters:
path | The path to the potential directory. |
|---|
Returns:
Whether the path exists and is a directory.
staticfileExists(path:String):Bool
Check if a path is a file on the filesystem. Only works on native.
Parameters:
path | The path to the potential file. |
|---|
Returns:
Whether the path exists and is a file.
staticgetDirSize(path:String):Int
Get a directory's total size in bytes. Max representable size is ~2.147 GB. Only works on native.
Parameters:
path | The path to the directory. |
|---|
Returns:
The total size of the directory in bytes.
staticgetFileSize(path:String):Int
Get a file's size in bytes. Max representable size is ~2.147 GB. Only works on native.
Parameters:
path | The path to the file. |
|---|
Returns:
The size of the file in bytes.
staticgetTempDir():Null<String>
Get the path to a temporary directory we can use for writing files. Only works on native.
Returns:
The path to the temporary directory.
staticmakeZIPEntry(name:String, content:String):Entry
Create a ZIP file entry from a file name and its string contents.
Parameters:
name | The name of the file. You can use slashes to create subdirectories. |
|---|---|
content | The string contents of the file. |
Returns:
The resulting entry.
staticmakeZIPEntryFromBytes(name:String, data:Bytes):Entry
Create a ZIP file entry from a file name and its string contents.
Parameters:
name | The name of the file. You can use slashes to create subdirectories. |
|---|---|
data | The byte data of the file. |
Returns:
The resulting entry.
staticmoveDir(path:String, destination:String, ?ignore:Array<String>, strict:Bool = true):Void
Move a directory from one location to another, optionally ignoring some paths. Only works on native.
Parameters:
path | The path to the directory. |
|---|---|
destination | The path to move the directory to. |
ignore | A list of paths to ignore. |
strict | Fails if the destination directory is not empty. |
staticmoveFile(path:String, destination:String):Void
Moves a file from one location to another. Only works on native.
Parameters:
path | The path to the file. |
|---|---|
destination | The path to move the file to. |
staticopenFolder(pathFolder:String, createIfNotExists:Bool = true):Void
Runs platform-specific code to open a path in the file explorer.
Parameters:
pathFolder | The path of the folder to open. |
|---|---|
createIfNotExists | If |
staticopenSelectFile(path:String):Void
Runs platform-specific code to open a file explorer and select a specific file.
Parameters:
path | The path of the file to select. |
|---|
staticpathExists(path:String):Bool
Check if a path exists on the filesystem. Only works on native.
Parameters:
path | The path to the potential file or directory. |
|---|
Returns:
Whether the path exists.
staticreadBytesFromPath(path:String):Bytes
Read bytes file contents directly from a given path. Only works on native.
Parameters:
path | The path to the file. |
|---|
Returns:
The file contents.
staticreadDir(path:String):Array<String>
List all entries in a directory. Only works on native.
Parameters:
path | The path to the directory. |
|---|
Returns:
An array of entries in the directory.
staticreadJSONFromPath(path:String):Dynamic
Read JSON file contents directly from a given path. Only works on native.
Parameters:
path | The path to the file. |
|---|
Returns:
The JSON data.
staticreadStringFromPath(path:String):String
Read string file contents directly from a given path. Only works on native.
Parameters:
path | The path to the file. |
|---|
Returns:
The file contents.
staticrename(path:String, newName:String, keepExtension:Bool = true):Void
Rename a file or directory. Only works on native.
Parameters:
path | The path to the file or directory. |
|---|---|
newName | The new name of the file or directory. |
keepExtension | Whether to keep the extension the same, if applicable. |
staticsaveChartAsFNFC(resources:Array<Entry>, ?onSave:Array<String> ‑> Void, ?onCancel:() ‑> Void, ?defaultPath:String, force:Bool = false):Bool
Takes an array of file entries and prompts the user to save them as a FNFC file.
staticsaveFile(data:Bytes, ?typeFilter:Array<FileFilter>, ?onSave:String ‑> Void, ?onCancel:() ‑> Void, ?defaultFileName:String, ?dialogTitle:String):Bool
Browses for a single file location, then writes the provided haxe.io.Bytes data and calls onSave(path) when done.
Works great on desktop and HTML5.
Returns:
Whether the file dialog was opened successfully.
staticsaveFilesAsZIP(resources:Array<Entry>, ?onSave:Array<String> ‑> Void, ?onCancel:() ‑> Void, ?defaultPath:String, force:Bool = false):Bool
Takes an array of file entries and prompts the user to save them as a ZIP file.
staticsaveFilesAsZIPToPath(resources:Array<Entry>, path:String, mode:FileWriteMode = Skip):Bool
Takes an array of file entries and forcibly writes a ZIP to the given path.
Only works on native, because HTML5 doesn't allow you to write files to arbitrary paths.
Use saveFilesAsZIP instead.
Parameters:
force | Whether to force overwrite an existing file. |
|---|
staticsaveMultipleFiles(resources:Array<Entry>, ?onSaveAll:Array<String> ‑> Void, ?onCancel:() ‑> Void, ?defaultPath:String, force:Bool = false):Bool
Prompts the user to save multiple files. On desktop, this will prompt the user for a directory, then write all of the files to there. On HTML5, this will zip the files up and prompt the user to save that.
Parameters:
typeFilter | TODO What does this do? |
|---|
Returns:
Whether the file dialog was opened successfully.
staticwriteBytesToPath(path:String, data:Bytes, mode:FileWriteMode = Skip):Void
Write byte file contents directly to a given path. Only works on native.
Parameters:
path | The path to the file. |
|---|---|
data | The bytes to write. |
mode | Whether to Force, Skip, or Ask to overwrite an existing file. |
staticwriteFileReference(path:String, data:String, callback:String ‑> Void):Void
Prompts the user to save a file to their computer.
staticwriteStringToPath(path:String, data:String, mode:FileWriteMode = Skip):Void
Write string file contents directly to a given path. Only works on native.
Parameters:
path | The path to the file. |
|---|---|
data | The string to write. |
mode | Whether to Force, Skip, or Ask to overwrite an existing file. |