Valnurat

Will this run for ever

5 posts in this topic

I'm trying to run through our users home directory for old backup folders that is not needed anymore. We have a backup solution that create a folder on users home directory. The name of the folder is the name of the computer. So when a users a getting a new computer the a new backup folder is created. And in time a lot of backup folders will be present if the user are not deleting them, but that is usually not the case. So we will go through all users home folder and delete what not needed anymore. To find out which computer that is active I use the AD attribute "managedby" on the computer object and I make an array of active computers for the user, so I don't delete wrong folders. But what I can't find out is if my 'DO ... UNTIL' runs for ever. I hope you guys can help me out here.

Func DelFolder()
  Local $aComputerOwner, $sFileDate, $hSearch, $sFileName = ""
  For $i = 0 To UBound($aUsersTarget) - 1
    $aComputerOwner = _AD_GetObjectsInOU("OU=computers," & $sSiteOU & ",OU=company,DC=AD,DC=company,DC=ORG","(&(objectclass=computer)(managedby=" & $aUsersTarget[$i][0] & "))",Default,"cn")
    if $aComputerOwner <> 0 Then
      $hSearch = FileFindFirstFile($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & "*.")
      if $hSearch <> -1 Then
        Do
          $sFileName = FileFindNextFile($hSearch)
          if UBound(_ArrayFindAll($aComputerOwner,$sFileName)) = 0 Then
            if StringInStr($sFileName,StringUpper(stringRight($sSiteOU,2) & StringMid($sSiteOU,StringInStr($sSiteOU,",")-2,2)&"LT")) <> 0 Or StringInStr($sFileName,StringUpper(stringRight($sSiteOU,2) & StringMid($sSiteOU,StringInStr($sSiteOU,",")-2,2)&"DT")) <> 0 Then
              $sFileDate = _ConvertTimeFormat(FileGetTime($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName,0,1))
                If _DateDiff('M', $sFileDate, _NowCalc()) > $sIntVal Then
                  if $aUsersTarget[$i][4] = "" Then             ;   HomePath                        Username
                    _FileWriteLog($hFile, $aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $sFileName&@CRLF)
                    if $bDebugMode Then
                      ConsoleWrite($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $sFileName& ' ' &_DateDiff('M', $sFileDate, _NowCalc())& ' ' &$sIntVal& ' ' & $aUsersTarget[$i][4] & @CRLF)
                    EndIf
                Else                    ;   HomePath                        Username                    BackupFolder
                    _FileWriteLog($hFile, $aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & $sFileName&@CRLF)
                    if $bDebugMode Then
                      ConsoleWrite($aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $sFileName& ' ' &_DateDiff('M', $sFileDate, _NowCalc())& ' ' &$sIntVal& ' ' & $aUsersTarget[$i][4] & @CRLF)
                    EndIf
                EndIf
              EndIf
            EndIf
          EndIf
        Until FileFindNextFile($hSearch) = @error
      Else
        _FileWriteLog($hFile, "Error: No files/directories matched for " & $aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & "*."&@CRLF)
        if $bDebugMode Then
          ConsoleWrite("Error: No files/directories matched for " & $aUsersTarget[$i][2] & "\" & $aUsersTarget[$i][3] & "\" & $aUsersTarget[$i][4] & "\" & "*."&@CRLF)
        EndIf
      EndIf
    ; Close the search handle.
      FileClose($hSearch)
    EndIf
  Next
EndFunc

 


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Put an expression that's never false:

Do
;...
Until True

A outer While...Wend in which the For...next is capsulated 

Edited by AutoBert

Share this post


Link to post
Share on other sites

Sorry I didn't understand that. :>


Yours sincerely

Kenneth.

Share this post


Link to post
Share on other sites

Just insert While True before actualy line 2 (For $i ...) and Wend before EndFunc.

 

Sorry, Inserting code don't works for me since 2 hours, so file with changes attached.

delFolders.au3

Share this post


Link to post
Share on other sites

That didn't helped, but I rewrote it and now it is working.

used the _FileListToArray function.

 

:)


Yours sincerely

Kenneth.

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

  • Similar Content

    • RoundChecker
      By RoundChecker
      Hi everyone,

      Is there a way to determine whether the script that is running, is already running, without using;
       
      If WinExists ?

      Or is there a way to use "If WinExists" to determine the script itself?

      The reason I am asking this is because if I want someone to run the .Exe I have and they rename it to whatever they want, how could I then determine in the script to check if there's already an .Exe open, or the script itself is already open?

      Should I use Class, or how do I achieve this?

      Thanks in advance.
    • svenjatzu
      By svenjatzu
      Id like to build a little helpertool for my boss in office but i dont know how to sart it.
      thats no complicated task. im working for an insurancecenter and have to search the customers in different orders and different tags.
      due to my boss is old and not really commen with pc he saves the customers without system.
      eg, customer andreas statham got an insurenca for his car then i got to search for
      andreas statham car, andreas car statham, car andreas statham, statham andreas car, statham car andreas, car statham andreass etc to find all the files from this customer in the harddrive.
      some customers also are fmiliarnamed in one file like andreas statam and monika rog are married an both got a carinsurance then i got to earch for
      andreas statham monika rog car, andreas statham monika car rog,.... this can take real long to find the right customer if i do it from hand.
      how can i realise this someone in here got an excamlple script or has any sugestion?
       
       
    • X_xkijux_x
      By X_xkijux_x
      Ok so im using this program. clarify for school. I would like to have a program that takes every word i type in microsoft word and searches on it in claryfi. is this possible. I would like to have the program not stopping me from typing more after that word. Like when i type a word it auto search it on clarify without making me stop typing and if i want to change i can do that and if im fine that word i can just keep typing and it will search after the next word. 
    • Miliardsto
      By Miliardsto
      Is this possible to make program works like in diagram? There is so much encryption methods and UDFs are they give security? If the $Address will be crypted with some encryption algorithm could be possible to get the value of $Address in easy way? Of course We know its easy too look into autoit code and get value of variable and so We dont want to anyone see $Address value - there are functions Could func1.au3, func2.au3.. be for example func1.php or other type of file? As we know .php files are unnable to see. For example func1 would be read by FileRead() and then Execute() Is this generally possible to do?
      Will it give secure?
      What do you think about? Maybe there is something wrong in this concept or missed.

    • JaredStroeb
      By JaredStroeb
      I need to open an application and send it keys in Session 0.  I have exe's working locally, I can see the application open in session 0 through interactive services, but my send commands do not go to the application.  The following article running-autoit-session-0, directs me to use ControlSend() however my application has no controls that can be identified by AutoIt v3 Window Info.  Get All Windows Controls also returned nothing for the application's handle.  
      What are my options?  
      Can this be done with AutoIt?
      Is there a different "relatively simple" library/tool to use? (I am familiar with C# if there is a viable library there )