# FileUtils

### Description

Set of utilites for working with files and text content.

Public API

Public API

### Functions

Public API

#### deprecated canonicalizeFolderPath

Warning: Contrary to the name, this does NOT return a canonical path. The canonical format used by Directory.fullPath actually DOES include the trailing "/"

path string
Returns: string
Public API

#### compareFilenames

Compares 2 filenames in lowercases. In Windows it compares the names without the extension first and then the extensions to fix issue #4409

filename1 string
filename2 string
extFirst boolean
If true it compares the extensions first and then the file names.
Returns: number
The result of the local compare function
Public API

#### convertToNativePath

Convert a URI path to a native path. On both platforms, this unescapes the URI On windows, URI paths start with a "/", but have a drive letter ("C:"). In this case, remove the initial "/".

path non-nullable string
Returns: string
Public API

#### convertToWindowsFilename

Converts filename to be available in Windows

filename string
Filename to be converted available in Windows
Returns: string
forbidden chars were replaced by "_"
Public API

#### convertWindowsPathToUnixPath

Convert a Windows-native path to use Unix style slashes. On Windows, this converts "C:\foo\bar\baz.txt" to "C:/foo/bar/baz.txt". On Mac, this does nothing, since Mac paths are already in Unix syntax. (Note that this does not add an initial forward-slash. Internally, our APIs generally use the "C:/foo/bar/baz.txt" style for "native" paths.)

path string
A native-style path.
Returns: string
A Unix-style path.

#### ensureTrailingSlash

Although this app is generally standardized on folder paths with a trailing "/", some APIs here receive project paths without "/" due to legacy preference storage formats, etc.

fullPath non-nullable string
Path that may or may not end in "/"
Returns: !string
Path that ends in "/"
Public API

#### getApplicationDirectoryPath

Returns the full path to the application directory.

Returns: !string
fullPath reference
Public API

#### getBaseName

Get the name of a file or a directory, removing any preceding path.

fullPath string
full path to a file or directory
Returns: string
Returns the base name of a file or the name of a directory
Public API

#### getDirectoryPath

Get the parent directory of a file. If a directory is passed in the directory is returned.

fullPath string
full path to a file or directory
Returns: string
Returns the path to the parent directory of a file or the path of a directory, including trailing "/"
Public API

#### getFileExtension

Get the file extension (excluding ".") given a path OR a bare filename. Returns "" for names with no extension. If the name starts with ".", the full remaining text is considered the extension.

fullPath string
full path to a file or directory
Returns: string
Returns the extension of a filename or empty string if the argument is a directory or a filename with no extension
Public API

#### getNativeDirectoryPath

Returns a native absolute path to the application source directory. Note that this only works when run in /src/index.html, so it does not work for unit tests (which is run from /test/SpecRunner.html)

WARNING: unlike most paths, this path EXCLUDES the trailing "/".

Returns: string
Public API

#### getNativeModuleDirectoryPath

Given the module object passed to JS module define function, convert the path to a native absolute path. Returns a native absolute path to the module folder.

WARNING: unlike most paths, this path EXCLUDES the trailing "/".

Returns: string
Public API

#### getPlatformLineEndings

Returns the standard line endings for the current platform

Returns: LINE_ENDINGS_CRLF,LINE_ENDINGS_LF
Public API

#### getRelativeFilename

Computes filename as relative to the basePath. For example: basePath: /foo/bar/, filename: /foo/bar/baz.txt returns: baz.txt

The net effect is that the common prefix is stripped away. If basePath is not a prefix of filename, then undefined is returned.

basePath string
Path against which we're computing the relative path
filename string
Full path to the file for which we are computing a relative path
Returns: string
relative path
Public API

#### isServerHtmlFileExt

Determine if file extension is a server html file extension.

filePath string
could be a path, a file name or just a file extension
Returns: boolean
Returns true if fileExt is in the list
Public API

#### isStaticHtmlFileExt

Determine if file extension is a static html file extension.

filePath string
could be a path, a file name or just a file extension
Returns: boolean
Returns true if fileExt is in the list
Public API