filesystemModule
MS Code Extension API / core/extensionAPI/modules/filesystemModule
core/extensionAPI/modules/filesystemModule
Interfaces
CopyOptions
Defined in: core/extensionAPI/modules/filesystemModule.ts:24
Properties
overwrite?
optionaloverwrite?:boolean
Defined in: core/extensionAPI/modules/filesystemModule.ts:26
Overwrite the destination if it already exists (default: true)
WriteOptions
Defined in: core/extensionAPI/modules/filesystemModule.ts:19
Properties
recursive?
optionalrecursive?:boolean
Defined in: core/extensionAPI/modules/filesystemModule.ts:21
Create intermediate directories if they do not exist (default: true)
Type Aliases
FilesystemModule
FilesystemModule =
ReturnType<typeofcreateFilesystemModule>
Defined in: core/extensionAPI/modules/filesystemModule.ts:237
Functions
createFilesystemModule()
createFilesystemModule(
_extId):object
Defined in: core/extensionAPI/modules/filesystemModule.ts:31
Parameters
_extId
string
Returns
copy
copy: (
fromPath,toPath,_options?) =>Promise<void>
Recursively copy a file or directory. On Android this handles non-empty directories correctly.
Parameters
fromPath
string
toPath
string
_options?
Returns
Promise<void>
Example
await mscode.fs.copy('/sdcard/project/src', '/sdcard/project/src-backup');
delete
delete: (
path) =>Promise<void>
Recursively delete a file or directory. Silently succeeds when the path does not exist.
Parameters
path
string
Returns
Promise<void>
Example
await mscode.fs.delete('/sdcard/project/dist');
exists
exists: (
path) =>Promise<boolean>
Check whether a path exists (file or directory).
Parameters
path
string
Returns
Promise<boolean>
Example
if (await mscode.fs.exists('/sdcard/project/.git')) {
// it's a git repo
}
mkdir
mkdir: (
path) =>Promise<void>
Create a directory (and any missing parents).
Parameters
path
string
Returns
Promise<void>
Example
await mscode.fs.mkdir('/sdcard/project/dist/assets');
readDir
readDir: (
path) =>Promise<FileStat[]>
List the entries inside a directory. Returns an empty array (never throws) when the path does not exist.
Parameters
path
string
Returns
Promise<FileStat[]>
Example
const entries = await mscode.fs.readDir('/sdcard/project/src');
const tsFiles = entries.filter(e => !e.isDirectory && e.name.endsWith('.ts'));
readFile
readFile: (
path) =>Promise<string>
Read a file's content as a UTF-8 string.
Parameters
path
string
Returns
Promise<string>
Example
const json = await mscode.fs.readFile('/sdcard/project/package.json');
const pkg = JSON.parse(json);
readJson
readJson: <
T>(path) =>Promise<T>
Read a file and parse it as JSON in one step. Throws a descriptive error when the file is missing or malformed.
Type Parameters
T
T = unknown
Parameters
path
string
Returns
Promise<T>
Example
const config = await mscode.fs.readJson<MyConfig>('/sdcard/project/.myextrc');
rename
rename: (
oldPath,newPath) =>Promise<void>
Rename or move a file or directory.
Parameters
oldPath
string
newPath
string
Returns
Promise<void>
Example
await mscode.fs.rename('/sdcard/project/old.ts', '/sdcard/project/new.ts');
stat
stat: (
path) =>Promise<FileStat|null>
Return basic metadata for a path without reading its content.
Returns null when the path does not exist.
Parameters
path
string
Returns
Promise<FileStat | null>
Example
const stat = await mscode.fs.stat('/sdcard/project/src');
if (stat?.isDirectory) console.log('it is a folder');
walk
walk: (
dirPath) =>Promise<string[]>
Recursively list ALL files under a directory (no directories included). Useful for walking a project tree.
Parameters
dirPath
string
Returns
Promise<string[]>
Example
const allTs = (await mscode.fs.walk('/sdcard/project/src'))
.filter(p => p.endsWith('.ts'));
writeFile
writeFile: (
path,content,_options?) =>Promise<void>
Write (or overwrite) a file with UTF-8 content. Parent directories are created automatically.
Parameters
path
string
content
string
_options?
Returns
Promise<void>
Example
await mscode.fs.writeFile('/sdcard/project/dist/bundle.js', compiledCode);
writeJson
writeJson: (
path,value,indent) =>Promise<void>
Serialize a value to JSON and write it to a file.
Parameters
path
string
value
unknown
indent?
number = 2
Returns
Promise<void>
Example
await mscode.fs.writeJson('/sdcard/project/.myextrc', { theme: 'dark' });