Instance Method インスタンスメソッド

copyItem(at:to:)

Copies the file at the specified URL to a new location synchronously. 指定されたURLでファイルを新しい場所に同期的にコピーします。

Declaration 宣言

func copyItem(at srcURL: URL, 
           to dstURL: URL) throws

Parameters パラメータ

srcURL

The file URL that identifies the file you want to copy. The URL in this parameter must not be a file reference URL. This parameter must not be nil. あなたがコピーすることを望むファイルを識別するファイルURL。このパラメータの中のURLは、ファイル参照URLであってはいけません。このパラメータは、nilであってはいけません。

dstURL

The URL at which to place the copy of srcURL. The URL in this parameter must not be a file reference URL and must include the name of the file in its new location. This parameter must not be nil. そこにsrcURLのコピーを置くことになるURL。このパラメータの中のURLは、ファイル参照URLであってはいけません、そしてそのファイルのそれの新しい場所での名前を含まなければなりません。このパラメータは、nilであってはいけません。

Return Value 戻り値

true if the item was copied successfully or the file manager’s delegate stopped the operation deliberately. Returns false if an error occurred. 項目がうまくコピーされたならば、またはファイルマネージャの持つ委任先が操作を故意に停止したならばtrue。エラーが発生したならばfalseを返します。

Discussion 議論

When copying items, the current process must have permission to read the file or directory at srcURL and write the parent directory of dstURL. If the item at srcURL is a directory, this method copies the directory and all of its contents, including any hidden files. If a file with the same name already exists at dstURL, this method stops the copy attempt and returns an appropriate error. If the last component of srcURL is a symbolic link, only the link is copied to the new path. 項目をコピーする場合、現在のプロセスはsrcURLでのファイルまたはディレクトリを読み込む、そしてdstURLの親ディレクトリに書き出す権限を持たなければなりません。srcURLでの項目がディレクトリならば、このメソッドはそのディレクトリとそれの内容の全てをコピーします、あらゆる不可視ファイルを含めて。同じ名前を持つファイルが既にdstURLで存在するならば、このメソッドはコピーの試みを停止して、適切なエラーを返します。srcURLの最後の構成要素がシンボリックリンクならば、そのリンクだけが新しいパスにコピーされます。

Prior to copying each item, the file manager asks its delegate if it should actually do so. It does this by calling the fileManager(_:shouldCopyItemAt:to:) method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the fileManager(_:shouldCopyItemAtPath:toPath:) method instead. If the delegate method returns true, or if the delegate does not implement the appropriate methods, the file manager proceeds to copy the file or directory. If there is an error copying an item, the file manager may also call the delegate’s fileManager(_:shouldProceedAfterError:copyingItemAt:to:) or fileManager(_:shouldProceedAfterError:copyingItemAtPath:toPath:) method to determine how to proceed. 各項目をコピーするに先だって、ファイルマネージャは、それが実際にそうするべきかそれの委任先に尋ねます。それはこれをfileManager(_:shouldCopyItemAt:to:)メソッドを呼び出すことによって行います; そのメソッドが実装されていない(またはプロセスがOS X 10.5以前で動作している)ならばそれはfileManager(_:shouldCopyItemAtPath:toPath:)メソッドを代わりに呼び出します。委任先メソッドがtrueを返すならば、または委任先が適切なメソッドを実装しないならば、ファイルマネージャがファイルまたはディレクトリのコピーを続行します。項目のコピーに関してエラーがあるならば、ファイルマネージャはまた委任先の持つfileManager(_:shouldProceedAfterError:copyingItemAt:to:)またはfileManager(_:shouldProceedAfterError:copyingItemAtPath:toPath:)メソッドを呼び出してどのように続けるか決定します。

See Also 参照

Moving and Copying Items 項目の移動とコピー