本文實例講述了JavaScript實現(xiàn)刪除,移動和復制文件的方法。分享給大家供大家參考。具體如下:
這里利用JavaScript刪除、移動和復制文件,運行前請確保文件已經(jīng)存在,比如在C盤建立test.txt文件,然后在代碼里修改為這個路徑,再運行代碼,就可以看到效果。
- <html>
- <head>
- <title>刪除,移動和復制文件</title>
- </head>
- <body>
- <h2>刪除,移動和復制文件</h2>
- <hr>
- <script language="JavaScript">
- var strSourFile = "c://test.txt";
- var strDestFile = "c://test//test.txt";
- var objFSO = new ActiveXObject("Scripting.FileSystemObject");
- // 檢查文件是否存在
- if (objFSO.FileExists(strSourFile)){
- // 移動文件
- var strPath = objFSO.MoveFile(strSourFile, strDestFile);
- if (objFSO.FileExists(strDestFile))
- document.write("文件已經(jīng)移動到: " + strDestFile + "<br>");
- // 復制文件
- var strPath = objFSO.CopyFile(strDestFile, strSourFile);
- if (objFSO.FileExists(strSourFile))
- document.write("文件已經(jīng)復制到: " + strSourFile + "<br>");
- // 刪除文件
- objFSO.DeleteFile(strDestFile, true);
- document.write("文件: " + strDestFile + "已經(jīng)刪除<br>");
- }
- else
- document.write("文件: " + strSourFile + "不存在<br>");
- </script>
- </body>
- </html>
新聞熱點
疑難解答
圖片精選