2016-06-07 175 views
1

我有編碼在AutoIt的小2行腳本像下面如何刪除文件與AutoIt的

#RequireAdmin 
FileDelete ("C:\Users\Administrator\Desktop\temp\") 

我想刪除目錄下的文件,但即使我想這代碼 -

#RequireAdmin 
DirRemove ("C:\Users\Administrator\Desktop\temp\") 
它不工作

但它沒有任何建議?

回答

2

爲FileDelete語法

FileDelete ("filename") ; not only directory! 

您也可以使用通配符文件名(*和?)。 Diskussion of wildcards: see Remarks here.

DirRemove工作過程如下:

DirRemove ("path" [, recurse = 0]) 

隨着遞歸= 0(默認),刪除該文件夾,只有當它是空的! 隨着recurse = 1刪除文件和子目錄(如DOS DelTree命令)。

編輯: 也許,你誤會了這種使用標誌。這就是爲什麼更詳細:

; Remove only the empty folder "Folder_path" 
DirRemove('Folder_Path') 

; Remove folder "Folder_Path" with all subfolder and all files within 
DirRemove('Folder_Path', 1) 

如果這不應該工作,它是一個系統權限的問題。

EDIT_2:如果你想刪除沒有根文件夾本身,你可以這樣做:

#include <Files.au3> 

; get all the files in root folder and delete them 
Local $aFilesInRoot = _FileListToArray('Your_Path', 1, True) ; 1=$FLTA_FILES = Return files only, True=returns full path 
For $i = 1 To $aFilesInRoot[0] 
    FileDelete($aFilesInRoot[1]) 
Next 

; now get all the subfolder under root and delete these all recursive 
Local $aFolderInRoot = _FileListToArray('Your_Path', 2, True); 2=$FLTA_FOLDERS = Return Folders only 
For $i = 1 To $aFolderInRoot[0] 
    DirRemove($aFolderInRoot[1], 1) 
Next 

但它是不容易刪除所有的只用一個命令後重拍刪除根文件夾?