DavidW Posted November 25, 2016 Share Posted November 25, 2016 (edited) Hi, Currently i made a script that deletes everything older then 7 days in a script. But for some reason when i create a folder in C:'\test and another folder IN the folder that i made. It will not get deleted by my script. But all other extensions like .txt .rar, etc. will get deleted succesfully in the folder that i made I uploaded a example image file for easier explaining. this is my script #include <File.au3> #include <Date.au3> $Folder = "C:\test\" $test = _FileListToArray($Folder) If IsArray($test) Then For $i = 1 To UBound($test) - 1 $tijd = StringRegExpReplace(FileGetTime($Folder & $test[$i], 1, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") If _DateDiff('D', $tijd, _NowCalc()) > 7 Then FileDelete($Folder & $test[$i]) DirRemove ($Folder & $test[$i]) EndIf Next EndIf I hope you guys can help me / point me in the right direction Solved the problem by changing the DirRemove command! Spoiler Edited November 25, 2016 by DavidW Link to comment Share on other sites More sharing options...
jguinch Posted November 25, 2016 Share Posted November 25, 2016 If the folder is not empty you have to force it to delete by using $DIR_REMOVE with DirRemove Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
InunoTaishou Posted November 25, 2016 Share Posted November 25, 2016 Quote Remarks Some directory attributes can make the deletion impossible, therefore if this is the case look at FileSetAttrib() to change the attributes of a directory. Idk what attributes your folder has. Tested your script on my system and it worked (just changed the difference date to 0 so it always executed) #include <File.au3> #include <Date.au3> $Folder = "C:\test\" $test = _FileListToArray($Folder) If IsArray($test) Then For $i = 1 To UBound($test) - 1 $tijd = StringRegExpReplace(FileGetTime($Folder & $test[$i], 1, 1), "(.{4})(.{2})(.{2})(.{2})(.{2})(.{2})", "${1}/${2}/${3} ${4}:${5}:${6}") If _DateDiff('D', $tijd, _NowCalc()) >= 0 Then ConsoleWrite("Removing folder " & $Folder & $test[$i] & " : " & (DirRemove($Folder & $test[$i]) ? "Succeeded" : "Failed") & @LF) EndIf Next EndIf Link to comment Share on other sites More sharing options...
DavidW Posted November 25, 2016 Author Share Posted November 25, 2016 6 minutes ago, jguinch said: If the folder is not empty you have to force it to delete by using $DIR_REMOVE with DirRemove Thanks problem solved! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now