DirCopy

Copies a folder along with all its sub-folders and files (similar to xcopy) or the entire contents of an archive file such as ZIP.

DirCopy Source, Dest , Overwrite

パラメータ

Source

型:文字列

ソースディレクトリの名前(末尾にバックスラッシュを付けない)。絶対パスが指定されていない場合は、A_WorkingDirにあると仮定されます。事例:C:\My Folder

If supported by the OS, Source can also be the path of an archive file, in which case its contents will be copied to the destination directory. ZIP files are always supported. TAR files require at least Windows 10 (1803) build 17063. RAR, 7z, gz and others require at least Windows 11 23H2 (which uses libarchive, where all supported formats are listed).

Dest

型:文字列

絶対パスが指定されていない場合、A_WorkingDirにあると仮定される宛先ディレクトリ名(末尾にバスクラッシュを付けない)。事例:C:\Copy of My Folder

Overwrite

型:整数

省略された場合、デフォルトは 0 です。Otherwise, specify one of the following numbers to indicate whether to overwrite files if they already exist:

0: Do not overwrite existing files. Destがすでにファイルまたはディレクトリとして存在する場合、操作は失敗し、何の効果もありません。

1: Overwrite existing files. ただし、Dest内のファイルやサブフォルダで、Sourceに対応するものがないものは削除されません。

その他の値は、将来の使用のために予約されています。

エラー処理

エラーが発生した場合は、例外がスローされます。

コピー元のディレクトリに、PageName.htmファイルとそれに対応するPageName_filesという名前のディレクトリからなる保存されたウェブページがある場合、コピーに成功しても例外が発生することがあります。

備考

保存先のディレクトリ構造が存在しない場合は、可能であれば作成されます。

この操作は、フォルダとそのすべてのサブフォルダおよびファイルを再帰的にコピーするため、フォルダをそれ自体の内部のどこかにコピーした場合の結果は未定義です。これを回避するには、まず自分以外の場所にコピーし、そのコピーをDirMoveで目的の場所に移動させます。

DirCopyは、1つのフォルダーをコピーします。フォルダの内容(そのすべてのファイルとサブフォルダ)を代わりにコピーするには、FileCopyの例のセクションを参照してください。

DirMove, FileCopy, FileMove, FileDelete, file loops, DirSelect, SplitPath

ディレクトリを新しい場所にコピーします。

DirCopy "C:\My Folder", "C:\Copy of My Folder"

フォルダーをコピーするよう促す。

SourceFolder := DirSelect(, 3, "Select the folder to copy")
if SourceFolder = ""
    return
; それ以外の場合は、続行します。
TargetFolder := DirSelect(, 3, "Select the folder IN WHICH to create the duplicate folder.")
if TargetFolder = ""
    return
; それ以外の場合は、続行します。
Result := MsgBox("A copy of the folder '" SourceFolder "' will be put into '" TargetFolder "'. Continue?",, 4)
if Result = "No"
    return
SplitPath SourceFolder, &SourceFolderName  ; フルパスからフォルダ名のみを抽出します。
try
    DirCopy SourceFolder, TargetFolder "\" SourceFolderName
catch
    MsgBox "The folder could not be copied, perhaps because a folder of that name already exists in '" TargetFolder "'."
return