File System
Name in Remix:
fileManagerkind:
fs
|Type |Name |Description |
|———|———————–|————|
|event |currentFileChanged |Triggered when a file changes.
|method |getCurrentFile |Get the name of the current file selected.
|method |open |Open the content of the file in the context (eg: Editor).
|method |writeFile |Set the content of a specific file.
|method |readFile |Return the content of a specific file.
|method |rename |Change the path of a file.
|method |copyFile |Upsert a file with the content of the source file.
|method |mkdir |Create a directory.
|method |readdir |Get the list of files in the directory.
Examples
Events
currentFileChanged: Triggered when a file changes.
client.solidity.on('currentFileChanged', (fileName: string) => {
// Do something
})
// OR
client.on('fileManager', 'currentFileChanged', (fileName: string) => {
// Do something
})
Methods
getCurrentFile: Get the name of the current file selected.
const fileName = await client.fileManager.getCurrentFile()
// OR
const fileName = await client.call('fileManager', 'getCurrentFile')
open:Open the content of the file in the context (eg: Editor).
await client.fileManager.open('browser/ballot.sol')
// OR
await client.call('fileManager', 'open', 'browser/ballot.sol')
readFile: Get the content of a file.
const ballot = await client.fileManager.getFile('browser/ballot.sol')
// OR
const ballot = await client.call('fileManager', 'readFile', 'browser/ballot.sol')
writeFile: Set the content of a file.
await client.fileManager.writeFile('browser/ballot.sol', 'pragma ....')
// OR
await client.call('fileManager', 'writeFile', 'browser/ballot.sol', 'pragma ....')
rename: Change the path of a file.
await client.fileManager.rename('browser/ballot.sol', 'browser/ERC20.sol')
// OR
await client.call('fileManager', 'rename', 'browser/ballot.sol', 'browser/ERC20.sol')
copyFile: Insert a file with the content of the source file.
await client.fileManager.copyFile('browser/ballot.sol', 'browser/NewBallot.sol')
// OR
await client.call('fileManager', 'copyFile', 'browser/ballot.sol', 'browser/NewBallot.sol')
mkdir: Create a directory.
await client.fileManager.mkdir('browser/ERC')
// OR
await client.call('fileManager', 'mkdir', 'browser/ERC')
readdir: Create a directory.
const files = await client.fileManager.readdir('browser/ERC')
// OR
const files = await client.call('fileManager', 'readdir', 'browser/ERC')
Type Definitions can be found here