diff --git a/docs/examples/file_system.md b/docs/examples/file_system.md new file mode 100644 index 0000000..6725699 --- /dev/null +++ b/docs/examples/file_system.md @@ -0,0 +1,30 @@ +# File System +Example of working with the file system using scripts + +```js +// Downloading a file from url +const url = "https://repo.instancify.app/snapshots/com/instancify/scriptify/script-js/1.0.3-SNAPSHOT/maven-metadata.xml"; +const fileName = "maven-metadata.xml"; + +if (!existsFile(fileName)) { + print(`File ${fileName} not found. Downloading...`) + downloadFromUrl(url, fileName) +} + +const foundFiles = []; + +// Search all files in the current folder +listFiles("").forEach(file => { + print(`Found file in folder ${file}.`) + // Get the file name and delete the file maven-metadata.xml + const foundFileName = normalizePath(file).replace(`${normalizePath(baseDir)}/`, ""); + if (foundFileName === fileName) { + print(`File ${file} found. Delete it.`); + deleteFile(file); + } + foundFiles.push(file); +}); + +// Write all saved current actions to a file +writeFile("summary.json", JSON.stringify(foundFiles)); +``` \ No newline at end of file