Jump to content
Sign in to follow this  
digitalexpl0it

Looking for multiple files in a directory

Recommended Posts

digitalexpl0it

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
iamtheky

; 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
digitalexpl0it

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
iamtheky

 

*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
Jewtus

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  

  • Similar Content

    • Siryx
      By Siryx
      So what i need is a function that I pass a starting date into and it counts up to the current date. Example:
      2009-05-30
      2009-05-31
      2009-06-01
      ...
      2018-06-18
      How would I do that? I found the Date.au3 in the includes but I can't find anything close to a time object like I'm used to working with in Java. I just need some $date = setDate(2009-05-30) and from there I could just add a day every time. I need this to be in the very format I stated earlier and from what I can see everytime related to date and time is automatically changed to my german locale.
      €: I already tried setDate but instead it changed my PCs clock. Not quite what i was looking for  
    • nacerbaaziz
      By nacerbaaziz

      Hello
      I have a question please
      How to show Islamic date in Autoit
      I mean
      for example
      Ramadan month
      And moharam month ... etc
      I hope my question is clear for you
      Thanks in advance
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • TheSaint
      By TheSaint
      Files Checklist
      Just a simple little (complex enough) program I whipped up, for a purpose ... but only too happy to share.
      It can of course be modified to do more, but at the moment just compares file names with or without path ... Location versus Checklist.
      There are of course other compare programs out there, most doing a lot more than mine (i.e. WinMerge or FileComparer). But I wanted something quick and simple with drag & drop, that uses up a smallish amount of screen real estate.
      NOTE - The SAVE button is also a LOAD one, and displays 'Load' when the list is empty. So you can save and load specific lists. While in SAVE mode, the button can also be used with CTRL held down, to ADD another list to existing (displayed one) ... combining as they say ... though not saved until you SAVE. CLEAR button removes a selected entry, or if used with CTRL held down, queries about removing all listed entries.
              
      Files Checklist v1.2.zip
      Files Checklist v1.3.zip
      Files Checklist v1.4.zip  (Includes a BUGFIX.)
        (source included)
      WARNING - While this program does not act on files or folders ADDED or CHECKED, you might act on the results, so I advise caution, and I also recommend using the new 'Relative' option in v1.3 or newer ... but you still need to understand what you are doing and what the results actually mean. Some basic examples in the next post.
      Enjoy!
      RELATED
      Users might also be interested in another somewhat related program of mine.
      DeleteIf Same
      Cheers!
    • Jury
      By Jury
      So I get:
      $aMatch[0] Date(1499295600000)   this is supposed to be 06 Jul 2017
      $aMatch[0] Date(1483574400000)  this is supposed to be 05 Jan 2017
      does anybody know the formula to calculate the date from the large number?  It doesn't seem to be anything to do with DateToDayValue.
      thanks in advance.
×