add a move-file-unique word to move a file into a directory without name clashes

db4
Doug Coleman 2009-10-15 15:28:35 -05:00
parent 2a893c9a2c
commit 211dce8cd7
2 changed files with 15 additions and 1 deletions

View File

@ -54,6 +54,13 @@ HELP: with-unique-directory
}
{ $description "Creates a directory with " { $link unique-directory } " and calls the quotation with the pathname on the stack using the " { $link with-temporary-directory } " combinator. The quotation can access the " { $link current-temporary-directory } " symbol for the name of the temporary directory. Subsequent unique files will be created in this unique directory until the combinator returns." } ;
HELP: move-file-unique
{ $values
{ "path" "a pathname string" } { "directory" "a directory" }
{ "path'" "a pathname string" }
}
{ $description "Moves " { $snippet "path" } " to " { $snippet "directory" } " by creating a unique file in this directory. Returns the new path." } ;
HELP: current-temporary-directory
{ $values
{ "value" "a path" }
@ -90,6 +97,8 @@ ARTICLE: "io.files.unique" "Unique files"
cleanup-unique-directory
}
"Default temporary directory:"
{ $subsections default-temporary-directory } ;
{ $subsections default-temporary-directory }
"Moving files into a directory safely:"
{ $subsections move-file-unique } ;
ABOUT: "io.files.unique"

View File

@ -70,6 +70,11 @@ PRIVATE>
: unique-file ( prefix -- path )
"" make-unique-file ;
: move-file-unique ( path directory -- path' )
[
"" unique-file [ move-file ] keep
] with-temporary-directory ;
{
{ [ os unix? ] [ "io.files.unique.unix" ] }
{ [ os windows? ] [ "io.files.unique.windows" ] }