Sign in to follow this  
Followers 0
digitalexpl0it

Looking for multiple files in a directory

5 posts in this topic

Hello,

I am trying to look into multiple folders for outlook OST's. What I need is if there are more than one, delete the oldest one in that directory then move to the next directory. I am not to sure on how to compare and detect multiple OSTs in a folder. So far my script will search all the subdirectories in a given path and prompt me with the OST's found. How to I check for more than one OST and delete the oldest?

Folder structure example:

OSTS
- user1
  - User1.ost
- User2
  - User2.ost
  -User2_dup.ost
Etc...

 

; Script Start - Add your code below here
#include <Array.au3> ; Only required to display the arrays
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $sOSTDir = "\\server1\osts\"

$aArray = _FileListToArrayRec($sOSTDir, "*.ost", $FLTAR_RECUR, $FLTAR_SORT)

for $i = 1 to $aArray[0]
    $time =  FileGetTime($sOSTDir & $aArray[$i], 2); 0 if for modified date
    $dmyyyy =  $time[3]& ":" & $time[4] & ":" & $time[5]&'_'&$time[1]& "/" & $time[2] & "/" & $time[0]
    msgbox(0,"test", $aArray[$i] & " | Date: " & $dmyyyy)
next

Any help would be appreciated. 

Share this post


Link to post
Share on other sites



; Script Start - Add your code below here
#include <Array.au3> ; Only required to display the arrays
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $sOSTDir = @ScriptDir

$aArray = _FileListToArrayRec($sOSTDir, "*.ost", $FLTAR_RECUR, $FLTAR_SORT , $FLTAR_FULLPATH)

Global $aOut[$aArray[0] + 1][2]

for $i = 1 to $aArray[0]
$aOut[$i][0] =  $aArray[$i]
$aOut[$i][1] =  FileGetTime($aArray[$i], 2 , 1); 0 if for modified date
next

_ArrayDelete($aOut , 0)

for $i = UBound($aOut) - 1 to 1 step - 1

 If stringinstr($aOut[$i][0] , "\") <> 0 Then
    If stringsplit($aOut[$i][0] , "\" , 2)[0] = stringsplit($aOut[$i - 1][0] , "\" , 2)[0] Then
       If $aOut[$i][1] < $aOut[$i - 1][1] Then
            _ArrayDelete($aOut , $i)
       Else
            _ArrayDelete($aOut , $i - 1)
        EndIf
    EndIf
 Else
      If $aOut[$i][1] < $aOut[$i - 1][1] Then
            _ArrayDelete($aOut , $i)
      Else
            _ArrayDelete($aOut , $i - 1)
      EndIf
 EndIf
next




_ArrayDisplay($aOut , "newest")

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

thank you for the reply, it seems to only pull the first created OST and not the last accessed

Share this post


Link to post
Share on other sites

 

*I do see a limitation in there that my stringsplit is really only legit for stuff that is relative or one subfolder deep, definitely have to make that more robust to eliminate the plethora of cases that break it.

For items relative and one subfolder deep that example should behave correctly, leaving $aOut to reflect only the item in the folder with the latest datetime (as shown in $aArray)


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Question, have you considered just using cmd?

Delolder

can be executed from autoit using a run or runwait command.

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

  • Similar Content

    • ur
      By ur
      In some systems the date is displayed in the Taskbar as
      10-01-2018
      And in some systems it is like, 1/10/2018
      And in some it is, 10-Jan-2018
      And in different formats.
       
      I wrote my code to convert 1/10/2018 to 10-01-2018
      Func TodaysDate() $NewDate = _DateTimeFormat(_NowCalcDate(),1) $Array = StringSplit( $NewDate , ',' ) _ArrayDelete($Array, 0) _ArrayDelete($Array, 0) $Array1 = StringSplit($Array[0],' ') RemoveEmptyArrayLines($Array1) ;Will return the present day's date with format dd-mmm-yyyy ;$Date = StringStripWS($Array1[2]&"-"&StringLeft($Array1[1], 3)&"-"&$Array[1], $STR_STRIPALL) $Date = StringStripWS($Array1[2]&"-"&changeDateformat(StringLeft($Array1[1], 3))&"-"&$Array[1], $STR_STRIPALL) return $Date EndFunc Func RemoveEmptyArrayLines(ByRef $arrLines) $intCount = 1 While $intCount < UBound($arrLines) $arrLines[$intCount] = StringStripWS($arrLines[$intCount],$STR_STRIPLEADING + $STR_STRIPTRAILING) If StringLen($arrLines[$intCount])=0 Then _ArrayDelete($arrLines, $intCount) $intCount = $intCount - 1 EndIf $intCount = $intCount + 1 WEnd EndFunc ;To convert mmm to mm format Func changeDateformat($sText) Local $sMsg = StringStripWS($sText, $STR_STRIPALL) Switch $sMsg Case "Jan" $sMsg = "01" Case "Feb" $sMsg = "02" Case "Mar" $sMsg = "03" Case "Apr" $sMsg = "04" Case "May" $sMsg = "05" Case "Jun" $sMsg = "06" Case "Jul" $sMsg = "07" Case "Aug" $sMsg = "08" Case "Sep" $sMsg = "09" Case "Oct" $sMsg = "10" Case "Nov" $sMsg = "11" Case "Dec" $sMsg = "12" EndSwitch return $sMsg EndFunc But again it will work on machines only with 1/10/2018.
      Is there any direct function which will give only in the format 10-01-2018, whatever the system settings is.?
      I tried all the arguments for _DateTimeFormat, but showing machine dependent settings only.
      Google given these two links in AutoIT but these are also for specific formats only,like mine.
       
      Please suggest.
    • kawliga751
      By kawliga751
      I have established how to get tomorrows date however I can't seem to figure out how to format the date into my required format of MM/DD/YYYY.  
      I have this:
      $today=_DateToDayValue(@YEAR,@MON,@MDAY) Dim $Y, $M, $D $tomorrow=_DayValueToDate($today+1, $Y, $M, $D) The _DateToDayValue seems to have a fixed format.  I've also tried a :
      $vardate = _DateAdd( 'd',1, _NowCalcDate()) with a "StringSplit" and/or StringFormat but the _NowCalcDate seems to also be fixed to a YYYY/MM/DD format.
      I'm sure I'm missing something simple but am at a loss.
      Any help would be MUCH appreciated
       
       
    • TheAutomator
      By TheAutomator
      How can you get the downloads folder in AutoIT?
      As far as i know there isn't a macro for it right? like @Downloads or something?
      The ugly solution would be typing in the whole path but what if the user has chosen another location?
      Need to clear that folder regularly on my work and on different accounts..
      regards, TheAutomator
    • ur
      By ur
      To get the current time stamp, I got the below code.
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #RequireAdmin ; Under Vista the Windows API "SetSystemTime" may be rejected due to system security $td = _Date_Time_GetSystemTime() $td = _Date_Time_SystemTimeToDateTimeStr($td) $td = StringReplace($td, " ", "_") $td = StringReplace($td, ":", "_") MsgBox(0,"",$td) But it is not giving the date or time of the timezone where the system is there.
      Please suggestt
    • ur
      By ur
      When I tried the below code, I am getting the date in mm-dd-yyyy format.
      But I require dd-mm-yyyy format.
      Can anyone suggest how to do that.
      Func TodaysDate() return StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-") EndFunc Earlier I tried dd-mmm-yyyy format and it is working with below code.
      Func TodaysDate() $NewDate = _DateTimeFormat(_NowCalcDate(),1) $Array = StringSplit( $NewDate , ',' ) _ArrayDelete($Array, 0) _ArrayDelete($Array, 0) $Array1 = StringSplit($Array[0],' ') RemoveEmptyArrayLines($Array1) $Date = StringStripWS($Array1[2]&"-"&StringLeft($Array1[1], 3)&"-"&$Array[1], $STR_STRIPALL) return $Date EndFunc Which is unnecessarily complicated I feel., the approach
      Now I need format of dd-mm-yyyy.
      Can anyone suggest how to do this.