當我需要複製整個資料夾時,我可以使用 `copy file()` 函數逐步複製該資料夾中的每個檔案。使用 `Files In Directory()` 函數取得資料夾中所有檔案的名稱,並循環複製檔案。
但是,如果我需要複製的資料夾包含子資料夾,使用「複製檔案」會導致錯誤。事實上,如果我需要複製的資料夾內有多層子資料夾,那麼編寫 JSL 程式碼就會變得很困難。
有沒有什麼好的建議可以解決複製包含多層子資料夾的問題?
您沒有足夠詳細地描述該問題,因此無法找到解決方案。
處理子資料夾時遇到什麼錯誤?您是嘗試將子資料夾檔案複製到不同磁碟機上的相同子資料夾,還是所有檔案最終都會放在一個資料夾中?
// Create Sample Flie in Document folder (a folder with one text file and a sub folder which also have a text file)
baseDir = "$DOCUMENTS";
dir = baseDir || "/" || Substitute( MDYHMS( Today() ), "/", "-", ":", "." );
Create Directory( dir );
theText = "Copy Test";
Save Text File( dir || "/0_Test Copy1.txt", theText );
dir2 = dir || "/" || Substitute( MDYHMS( Today() ), "/", "-", ":", "." );
Create Directory( dir2 );
Save Text File( dir2 || "/Test Copy2.txt", theText );
//Copy Sample Files
Wait( 1 );
CopyFilesList = Files In Directory( dir );
CopyPath= baseDir || "/" || Substitute( MDYHMS( Today() ), "/", "-", ":", "." );
//The error message appears when the copy target is a folder.
For( Count = 1, Count <= N Items( CopyFilesList ), Count++,
Copy File( dir || "/" || CopyFilesList[Count], CopyPath || "/" || CopyFilesList[Count] )
);
運行上述範例後出現錯誤訊息。當複製目標是資料夾時,會出現錯誤訊息。