Sign in to follow this  
Followers 0
ileandros

How to delete items/folders based on date?

3 posts in this topic

#1 ·  Posted (edited)

Hi,

I wanted to use FileDelete commands to read some folders from a list and delete them but unfortunatly it isnt working as i wanted to.

As i read from the help files i found this "Some file attributes can make the deletion impossible.".I found the same in the DirRemove command...

Even that this is written in both commands DirRemove seems to work better than FileDelete.

This is my code:

#include <GUIConstantsEx.au3>
#include <File.au3>
#include <Array.au3>
#include "RecFileListToArray.au3"
$sRoot = @DesktopDir
Global $asList = TimeDate($sRoot)
Example()
Func Example()
$guicreate = GUICreate("Files/Folders", 500, 300)
$List = GUICtrlCreateList("",10,10,300,150)
$filemenu = GUICtrlCreateMenu("&File")
$fileitems = GUICtrlCreateMenuItem("DesktopDir", $filemenu)
$DE = GUICtrlCreateButton("Delete Files by Date", 10 , 250 , 120 , 25)
$DEinput = GUICtrlCreateInput("yyyy/mm/dd",160,250,120,25)
$EX = GUICtrlCreateButton("Check Date And Time", 10, 190,120,25)
GUISetState()
while 1
$msg = GUIGetMsg()
If $msg = $GUI_EVENT_CLOSE Then ExitLoop

Switch $msg
     Case $fileitems
     GUICtrlSetData($List,"")
     $sExt_String = "*"
     $sPath = @DesktopDir
     $aFiles = _RecFileListToArray($sPath, $sExt_String, 2)
     For $i = 1 To $aFiles[0]
     GUICtrlSetData($List, $aFiles[$i])
     Next
    Case $EX
     $asList = TimeDate($sRoot)
     _ArrayDisplay($asList,0,0,0,0,0,"Count|Folders|Date|Time")
     Case $DE
     $read = GUICtrlRead($List)
     if $read = true Then
     DirRemove($sPath & "" &$read,1)
     EndIf
EndSwitch
WEnd
EndFunc
Func TimeDate($sDir)
Local $aIn = _FileListToArray($sDir, "*", 2)
Local $aOut[$aIn[0] + 1][3] = [[$aIn[0]]]
For $i = 1 To $aOut[0][0]
     $aOut[$i][0] = $aIn[$i]
     $aDT = FileGetTime($sDir & "" & $aIn[$i], 0)
     $aOut[$i][1] = $aDT[0] & "/" & $aDT[1] & "/" & $aDT[2]
     $aOut[$i][2] = $aDT[3] & ":" & $aDT[4] & ":" & $aDT[5]
Next
Return $aOut
EndFunc

How can i make the $DE button delete folders that have the same date as the date that will give in the input???

I tried StringMid to get the date of the input and the test it with the date of the folders but without luck...

All kind of help will be appreciated. Thanks in advance.

Edit: Removing useless code.

Edited by ileandros

I feel nothing.It feels great.

Share this post


Link to post
Share on other sites



$read is only getting any information if you've clicked on a folder name in the Listbox, it doesn't do any date checking in the $DE case, it just deletes what you have highlighted. Perhaps you want to read the $DEInput control to get the date first, then loop through your array to get any folders that match that date, and delete them?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewManNH

Hey my friend. Sorry but im out of country and didnt really had time to log in.

Yes this is what i want to do. I already did that but i screwed it up thats why i posted this way.

My problem is that i cant loop right through my array. TimeDate() function isnt sth i made and its confusing me...


I feel nothing.It feels great.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0