Files and directories¶
Operations are recursive by default.
1 2 3 4 5 6 |
|
Moving around and temp dirs¶
- Changing to a non-existent directory will create it.
cd
can take a code block which changes the workingdir
only for the duration of that block.mktmp
returns a temp directory that will be recursively deleted when the script terminates.
1 2 3 4 5 6 7 8 9 10 11 |
|
Copying and moving files¶
1 2 |
|
cp
and mv
have more useful behavior than the UNIX cp command.
cp¶
- Overlays. If
source
is a directory anddest
is a pre-existing directory, the contents of source are recursively copied intodest
, replacing whatever was there. That is,source/foo
is copied todestination/foo
notdestination/source/foo
as you may expect given the behaviour of the UNIXcp
command. If you want that behaviour specify the destination as a subdirectory with the same name assource
e.g.cp("src", "dest/src")
. - File to directory. If
source
is a file anddest
is a pre-existing directory, it is copied into that directory with the same name, overwriting any file with the same name that's already there. - Creates directories. If
source
is a file anddest
does not exist, destination is treated as a file and the directory it's in is created along with all parents. - File overwrites. If
source
is a file anddest
is a file in a pre-existing directory, it is copied to that given path exactly, replacing the file. - If
source
is a directory anddest
is a pre-existing file,IllegalStateException
is thrown.
mv¶
mv
moves from
to to
, overwriting or merging with to
if it exists.
This command has subtly different semantics to the shell mv
command or Files.move
. It allows you to move a directory 'over'
another directory without throwing a DirectoryNotEmptyException
. If to
is a directory and isn't empty, then instead of it
being moved into that directory with the same name, each file is moved individually with directories being created as necessary
in the destination, giving a form of merge semantics. If you want to move a directory to a subdirectory of somewhere else, you
should therefore re-specify the source directory name as the last component of the target path.
However, if you try to move a file to a directory then it will be moved into that directory with the same name.
Warning
Currently extended attributes won't be copied when doing a merge, nor is the move atomic.
Hashing¶
1 2 |
|
Permissions¶
Permissions are mapped to their equivalents on Windows.
1 2 3 |
|
Archives¶
1 2 3 4 5 6 7 8 |
|
The tar function also supports tar.bz2
, tar.xz
and tar.Z
. Compression level can be controlled via zipOptions.compressionLevel
. Single
files can also be archived, and will be placed in the root.
Finding things¶
1 2 3 |
|
Disk usage¶
1 2 |
|
Accounting of hard links can be controlled.
Extended attributes¶
Also works on Windows.
1 2 |
|
Open in a GUI app¶
1 2 |
|