Simple File module to do basic operations
| Name | Description |
|---|---|
| baseNameOf | Returns the base name of this file |
| contentOf | Returns the content of the given path |
| copyTo | Copies the specified binary into the given path. |
| exists | Returns true if the file exits |
| extensionOf | Returns the extension of the file with the dot. |
| home | Returns the Path value of the home directory. |
| kindOf | Returns the file type. "File" or "Folder" or null if it doesn't exits |
| ls | Returns the list child file path |
| mimeTypeOf | Tries to guess the mimeType of the given Path |
| mkdir | Creates the a folder in the given path. And returns the path. |
| nameOf | Returns the name of this file |
| parentOf | Returns the path to the parent folder of a given file. |
| path | Creates a valid path with the specified parts |
| rm | Removes the file at the given location. Returns true if the file or folder was removed. |
| separator | Returns the system-dependent default name-separator character, represented as a string for convenience. |
| tmp | Returns the Path value of the tmp directory. |
| toUrl | Transform the specified file path into a valid Url |
| tree | |
| unzipTo | Unzips the specified file into the given directory |
| wd | Returns the Path value of the working directory. |
| writeTo | |
| zipInto | Zips the specified collection of files into the given zip path. |
| Name | Description |
|---|---|
| FILE_EXTENSIONS: { _: String } | Mapping between file extension and MimeType |
| Name | Description |
|---|---|
| FileKind | The two kind of file |
| Path |
baseNameOf ↑↑
Returns the base name of this file
| Name | Description |
|---|---|
| path |
This example shows how the baseNameOf behaves under different inputs.
%dw 2.0
output application/json
---
dw::io::file::FileSystem::baseNameOf("/tmp/a/test.json")
"test"contentOf ↑↑
Returns the content of the given path
| Name | Description |
|---|---|
| path | The path of the file |
This example shows how the contentOf behaves under different inputs.
%dw 2.0
output application/json
---
contentOf("/tmp/foo/bar.txt") as String {encoding: "UTF-8"}
"Hello"copyTo ↑↑
Copies the specified binary into the given path.
| Name | Description |
|---|---|
| binary | The content to be written |
| path | The path were is going to be written |
This example shows how the writeTo behaves under different inputs.
%dw 2.0
output application/json
---
copyTo( "Hello" as Binary {encoding: "UTF-8"}, "/tmp/foo/bar.txt")5exists ↑↑
Returns true if the file exits
| Name | Description |
|---|---|
| path | The path to be checked |
This example shows how the exists behaves under different inputs.
%dw 2.0
output application/json
---
dw::io::file::FileSystem::exists("/tmp")
trueextensionOf ↑↑
Returns the extension of the file with the dot.
| Name | Description |
|---|---|
| path | The path |
This example shows how the extensionOf behaves under different inputs.
%dw 2.0
output application/json
---
%dw 2.0
import * from dw::io::file::FileSystem
output application/json
---
{
a: extensionOf(path("/tmp","foo.txt")),
b: extensionOf(path("/tmp","foo.html")),
c: extensionOf(path("/tmp","foo.json")),
d: extensionOf(tmp()) //Directory should return null
}
{
"a": ".txt",
"b": ".html",
"c": ".json",
"d": null
}home ↑↑
Returns the Path value of the home directory.
kindOf ↑↑
Returns the file type. "File" or "Folder" or null if it doesn't exits
ls ↑↑
Returns the list child file path
| Name | Description |
|---|---|
| folder | The of the contained file |
This example shows how the ls behaves under different inputs.
%dw 2.0
output application/json
---
ls("/tmp")
["/tmp/foo.txt","/tmp/dw-input-buffer-0.tmp","/tmp/dw-output-buffer-0.tmp"]Return the list of child elements of the specified path. That matches the specified regex pattern
| Name | Description |
|---|---|
| folder | The of the contained file |
| filterExpr | The file expression regex to be used on each name |
This example shows how to filter tmp file to all the one that contains the text 'dw'
%dw 2.0
output application/json
---
ls("/tmp", /dw/)
["/tmp/dw-input-buffer-0.tmp","/tmp/dw-output-buffer-0.tmp"]mimeTypeOf ↑↑
Tries to guess the mimeType of the given Path
| Name | Description |
|---|---|
| path | The path |
This example shows how the mimeTypeOf behaves under different inputs.
%dw 2.0
output application/json
---
dw::io::file::FileSystem::mimeTypeOf("/tmp/test.json")
"application/json"mkdir ↑↑
Creates the a folder in the given path. And returns the path.
| Name | Description |
|---|---|
| path | The path to be created |
This example shows how the mkdir behaves under different inputs.
%dw 2.0
output application/json
---
mkdir("/tmp/a")
"/tmp/a"nameOf ↑↑
Returns the name of this file
parentOf ↑↑
Returns the path to the parent folder of a given file.
| Name | Type | Description |
|---|---|---|
| path | Path | The path to the file of interest. |
This example shows how the parentOf behaves under different inputs.
%dw 2.0
output application/json
import parentOf from dw::io::file::FileSystem
---
parentOf("tmp/someDir/someFile.txt")
"tmp/someDir"path ↑↑
Creates a valid path with the specified parts
| Name | Description |
|---|---|
| basePath | The base path |
| part | The child path to append |
This example shows how the path behaves under different inputs.
%dw 2.0
output application/json
---
path("/tmp/a","b")
"/tmp/a/b"Creates a valid Path with the specified parts
| Name | Description |
|---|---|
| basePath | The base path |
| part | Child Part 1 |
| part2 | Child Part 2 |
This example shows how the path behaves under different inputs.
%dw 2.0
output application/json
---
path("/tmp", "a","b")
"/tmp/a/b"Creates a valid Path with the specified parts
| Name | Description |
|---|---|
| basePath | The base path |
| part | Child Part 1 |
| part2 | Child Part 2 |
| part3 | Child Part 3 |
This example shows how the path behaves under different inputs.
%dw 2.0
output application/json
---
path("/tmp", "a","b","c")
"/tmp/a/b/c"Creates a valid Path with the specified parts
| Name | Description |
|---|---|
| basePath | The base path |
| parts | All that child part |
This example shows how the path behaves under different inputs.
%dw 2.0
output application/json
---
path("/tmp", ["a","b","c"])
"/tmp/a/b/c"rm ↑↑
Removes the file at the given location. Returns true if the file or folder was removed.
If the path is a file it will delete everything recursively.
| Name | Description |
|---|---|
| path | The path to delete |
This example shows how the rm behaves under different inputs.
%dw 2.0
import rm from dw::io::file::FileSystem
output application/json
---
rm("/home/dw/toRemove")
trueseparator ↑↑
Returns the system-dependent default name-separator character, represented as a string for convenience.
This example shows how the separator behaves under different inputs.
%dw 2.0
output application/json
import separator from dw::io::file::FileSystem
---
// Will return "/" for Unix-based systems, and "\" for Windows-based systems.
separator()
"/"tmp ↑↑
Returns the Path value of the tmp directory.
toUrl ↑↑
Transform the specified file path into a valid Url
| Name | Description |
|---|---|
path |
The path to be converted |
This example shows how the toUrl behaves under different inputs.
%dw 2.0
output application/json
---
toUrl( "/tmp/Application Test")
"file:/tmp/Application%20Test"tree ↑↑
unzipTo ↑↑
Unzips the specified file into the given directory
| Name | Description |
|---|---|
| zipPath | |
| targetDirectory |
This example shows how the unzipTo behaves under different inputs.
%dw 2.0
import * from dw::io::file::FileSystem
output application/json
---
fileToUnzip unzipTo path(tmp(), "dw_io_test" ,"outputZip")
"/tmp/dw_io_test/outputZip"wd ↑↑
Returns the Path value of the working directory.
writeTo ↑↑
zipInto ↑↑
Zips the specified collection of files into the given zip path.
| Name | Description |
|---|---|
| paths | The array of paths to be zipped |
| zipPath | The zip file path to be created |
This example shows how the zipInto behaves under different inputs.
%dw 2.0
import * from dw::io::file::FileSystem
output application/json
---
[path(tmp(),"dw_io_test")] zipInto path(tmp(),"outputZip.zip")
"/tmp/outputZip.zip"FILE_EXTENSIONS: { _: String } ↑↑
Mapping between file extension and MimeType
FileKind ↑↑
The two kind of file
"File" | "Folder"Path ↑↑
String