### Import : ```js const FileUtils = brackets.getModule("file/FileUtils") ``` ## LINE\_ENDINGS\_CRLF : enum Line endings crlf **Kind**: global enum ## LINE\_ENDINGS\_LF : enum Line endings lf **Kind**: global enum ## Maximium : Number file size (in bytes) This must be a hard-coded value since this value tells how low-level APIs should behave which cannot have a load order dependency on preferences manager **Kind**: global constant ## readAsText(file, bypassCache, [options]) ⇒ $.Promise Asynchronously reads a file as UTF-8 encoded text. **Kind**: global function **Returns**: $.Promise - a jQuery promise that will be resolved with the file's text content plus its timestamp, or rejected with a FileSystemError string constant if the file can not be read. | Param | Type | Description | | --- | --- | --- | | file | File | File to read | | bypassCache | boolean | an optional argument, if specified will read from disc instead of using cache. | | [options] | object | | | [options.ignoreFileSizeLimits] | boolean | Will read larger files than 16MB limit. will bypassCache + won't cache if enabled. | | [options.doNotCache] | boolean | will not cache if enabled. Auto-enabled if ignoreFileSizeLimits = true | ## writeText(file, text, [allowBlindWrite]) ⇒ $.Promise Asynchronously writes a file as UTF-8 encoded text. **Kind**: global function **Returns**: $.Promise - a jQuery promise that will be resolved when file writing completes, or rejected with a FileSystemError string constant. | Param | Type | Description | | --- | --- | --- | | file | File | File to write | | text | string | | | [allowBlindWrite] | boolean | Indicates whether or not CONTENTS_MODIFIED errors---which can be triggered if the actual file contents differ from the FileSystem's last-known contents---should be ignored. | ## getPlatformLineEndings() ⇒ [LINE\_ENDINGS\_CRLF](#LINE_ENDINGS_CRLF) \| [LINE\_ENDINGS\_LF](#LINE_ENDINGS_LF) Returns the standard line endings for the current platform **Kind**: global function ## sniffLineEndings(text) ⇒ null \| [LINE\_ENDINGS\_CRLF](#LINE_ENDINGS_CRLF) \| [LINE\_ENDINGS\_LF](#LINE_ENDINGS_LF) Scans the first 1000 chars of the text to determine how it encodes line endings. Returns null if usage is mixed or if no line endings found. **Kind**: global function | Param | Type | | --- | --- | | text | string | ## translateLineEndings(text, lineEndings) ⇒ string Translates any line ending types in the given text to the be the single form specified **Kind**: global function | Param | Type | | --- | --- | | text | string | | lineEndings | null \| [LINE\_ENDINGS\_CRLF](#LINE_ENDINGS_CRLF) \| [LINE\_ENDINGS\_LF](#LINE_ENDINGS_LF) | ## getFileErrorString(name) ⇒ string **Kind**: global function **Returns**: string - User-friendly, localized error message | Param | Type | | --- | --- | | name | FileSystemError | ## makeDialogFileList(Array) Creates an HTML string for a list of files to be reported on, suitable for use in a dialog. **Kind**: global function | Param | Type | Description | | --- | --- | --- | | Array | Array.<string> | of filenames or paths to display. | ## convertToNativePath(path) ⇒ string 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 "/". **Kind**: global function | Param | Type | | --- | --- | | path | string | ## convertWindowsPathToUnixPath(path) ⇒ string 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.) **Kind**: global function **Returns**: string - A Unix-style path. | Param | Type | Description | | --- | --- | --- | | path | string | A native-style path. | ## stripTrailingSlash(path) ⇒ string Removes the trailing slash from a path or URL, if it has one. Warning: this differs from the format of most paths used in Brackets! Use paths ending in "/" normally, as this is the format used by Directory.fullPath. **Kind**: global function | Param | Type | Description | | --- | --- | --- | | path | string | or URL | ## getBaseName(fullPath) ⇒ string Get the name of a file or a directory, removing any preceding path. **Kind**: global function **Returns**: string - Returns the base name of a file or the name of a directory | Param | Type | Description | | --- | --- | --- | | fullPath | string | full path to a file or directory | ## getNativeBracketsDirectoryPath() ⇒ string Returns a native absolute path to the 'brackets' source directory. Note that this only works when run in brackets/src/index.html, so it does not work for unit tests (which is run from brackets/test/SpecRunner.html) WARNING: unlike most paths in Brackets, this path EXCLUDES the trailing "/". **Kind**: global function ## getNativeModuleDirectoryPath() ⇒ string 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 in Brackets, this path EXCLUDES the trailing "/". **Kind**: global function ## getFileExtension(fullPath) ⇒ string 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. **Kind**: global function **Returns**: string - Returns the extension of a filename or empty string if the argument is a directory or a filename with no extension | Param | Type | Description | | --- | --- | --- | | fullPath | string | full path to a file or directory | ## getRelativeFilename(basePath, filename) ⇒ string 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. **Kind**: global function **Returns**: string - relative path | Param | Type | Description | | --- | --- | --- | | 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 | ## isStaticHtmlFileExt(filePath) ⇒ boolean Determine if file extension is a static html file extension. **Kind**: global function **Returns**: boolean - Returns true if fileExt is in the list | Param | Type | Description | | --- | --- | --- | | filePath | string | could be a path, a file name or just a file extension | ## getDirectoryPath(fullPath) ⇒ string Get the parent directory of a file. If a directory is passed, the SAME directory is returned. **Kind**: global function **Returns**: string - Returns the path to the parent directory of a file or the path of a directory, including trailing "/" | Param | Type | Description | | --- | --- | --- | | fullPath | string | full path to a file or directory | ## getParentPath(fullPath) ⇒ string Get the parent folder of the given file/folder path. Differs from getDirectoryPath() when 'fullPath' is a directory itself: returns its parent instead of the original path. (Note: if you already have a FileSystemEntry, it's faster to use entry.parentPath instead). **Kind**: global function **Returns**: string - Path of containing folder (including trailing "/"); or "" if path was the root | Param | Type | Description | | --- | --- | --- | | fullPath | string | full path to a file or directory | ## getFilenameWithoutExtension(filename) ⇒ string Get the file name without the extension. Returns "" if name starts with "." **Kind**: global function **Returns**: string - Returns the file name without the extension | Param | Type | Description | | --- | --- | --- | | filename | string | File name of a file or directory, without preceding path | ## compareFilenames(filename1, filename2, extFirst) ⇒ number Compares 2 filenames in lowercases. In Windows it compares the names without the extension first and then the extensions to fix issue #4409 **Kind**: global function **Returns**: number - The result of the compare function | Param | Type | Description | | --- | --- | --- | | filename1 | string | | | filename2 | string | | | extFirst | boolean | If true it compares the extensions first and then the file names. | ## comparePaths(path1, path2) ⇒ number Compares two paths segment-by-segment, used for sorting. When two files share a path prefix, the less deeply nested one is sorted earlier in the list. Sorts files within the same parent folder based on `compareFilenames()`. **Kind**: global function **Returns**: number - -1, 0, or 1 depending on whether path1 is less than, equal to, or greater than path2 according to this ordering. | Param | Type | | --- | --- | | path1 | string | | path2 | string | ## encodeFilePath(path) ⇒ string **Kind**: global function **Returns**: string - URI-encoded version suitable for appending to 'file:///`. It's not safe to use encodeURI() directly since it doesn't escape chars like "#". | Param | Type | Description | | --- | --- | --- | | path | string | Native path in the format used by FileSystemEntry.fullPath | ## shouldOpenInExternalApplication(ext) ⇒ string **Kind**: global function **Returns**: string - returns true If file to be opened in External Application. | Param | Type | Description | | --- | --- | --- | | ext | string | extension string a file | ## addExtensionToExternalAppList(ext) **Kind**: global function | Param | Type | Description | | --- | --- | --- | | ext | string | File Extensions to be added in External App List |