Jump to content

Recommended Posts

Posted

Hi

I've batch file (backup.bat). It contains following command :-

forfiles /p C:\inetpub\logs\LogFiles\W3SVC1 /m *.log /D -30 /C "cmd /c copy @file D:\Backup\BackupTemp"

"C:\Program Files (x86)\7-Zip\7z.exe" a D:\Datacap\Taskmaster_logs\"%DATE:~7,2%.%DATE:~4,2%.%DATE:~10,4%-backup".zip D:\Datacap\Taskmaster_logs\tms.log

Now want to translate to au3 file but failed...

RunWait(@ComSpec & ' /k'& '"forfiles /p C:\inetpub\logs\LogFiles\W3SVC1 /m *.log /D -30 /C ""cmd /c copy @file D:\Backup\BackupTemp""')

RunWait(@ComSpec & ' /k'& '""C:\Program Files (x86)\7-Zip\7z.exe"" a D:\Datacap\Taskmaster_logs\""%DATE:~7,2%.%DATE:~4,2%.%DATE:~10,4%-backup"".zip D:\Datacap\Taskmaster_logs\tms.log')

Anyone can translate it to me ? Thx in advance...

Posted

when in doubt... cheat...

 

 

Take any working script and turn it into binary, then call it from your script. I use this tool a whole lot.. love it.

C0d3 is P0etry( ͡° ͜ʖ ͡°)

  • Moderators
Posted

@epo it would help if you would tell us what part is failing, rather than just a general "it's broke" scenario. The first part of your batch files is basically saying "For all files in path C:\inetpub\logs\LogFiles\W3SVC1 that are older than 30 days and follow the format *.log, copy to D:\Backup\BackupTemp". Is this piece working for you (are the files copied successfully), and it is failing on the zip piece, or is it not even copying the files?

 

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

You can do this:

#include <Process.au3>
_RunDOS('forfiles /p C:\inetpub\logs\LogFiles\W3SVC1 /m *.log /D -30 /C "cmd /c copy @file D:\Backup\BackupTemp"')
_RunDOS('"C:\Program Files (x86)\7-Zip\7z.exe" a D:\Datacap\Taskmaster_logs\"%DATE:~7,2%.%DATE:~4,2%.%DATE:~10,4%-backup".zip D:\Datacap\Taskmaster_logs\tms.log')

Or this (test it first):

#include <File.au3>
#include <Date.au3>

$aFiles = _FileListToArray("C:\inetpub\logs\LogFiles\W3SVC1", "*.log", $FLTA_FILES, True)

For $i = 0 To $aFiles[0]
    ; get file modification date
    $dLastModified = FileGetTime($aFiles[$i])
    $dLastModified = $dLastModified[0] & "/" & $dLastModified[1] & "/" & $dLastModified[2] & " " & $dLastModified[3] & ":" & $dLastModified[4] & ":" & $dLastModified[5]

    ; gets the date difference
    $iDateDiff = _DateDiff("D", $dLastModified, _NowCalc())


    If $iDateDiff >= 30 Then
        FileCopy($aFiles[$i], "D:\Backup\BackupTemp\")
    EndIf
Next

ShellExecuteWait("C:\Program Files (x86)\7-Zip\&z.exe", "a D:\Datacap\Taskmaster_logs\" & @MDAY & "." & @MON & "." & @YEAR & "-backup.zip D:\Datacap\Taskmaster_logs\tms.log")

 

My stuff

  Reveal hidden contents

 

Posted
  On 12/8/2015 at 7:19 PM, JLogan3o13 said:

@epo it would help if you would tell us what part is failing, rather than just a general "it's broke" scenario. The first part of your batch files is basically saying "For all files in path C:\inetpub\logs\LogFiles\W3SVC1 that are older than 30 days and follow the format *.log, copy to D:\Backup\BackupTemp". Is this piece working for you (are the files copied successfully), and it is failing on the zip piece, or is it not even copying the files?

 

Hi

Yes it's working when running in batch mode (batch.bat)...

Posted (edited)
  On 12/8/2015 at 7:24 PM, Jefrey said:

You can do this:

#include <Process.au3>
_RunDOS('forfiles /p C:\inetpub\logs\LogFiles\W3SVC1 /m *.log /D -30 /C "cmd /c copy @file D:\Backup\BackupTemp"')
_RunDOS('"C:\Program Files (x86)\7-Zip\7z.exe" a D:\Datacap\Taskmaster_logs\"%DATE:~7,2%.%DATE:~4,2%.%DATE:~10,4%-backup".zip D:\Datacap\Taskmaster_logs\tms.log')

Or this (test it first):

#include <File.au3>
#include <Date.au3>

$aFiles = _FileListToArray("C:\inetpub\logs\LogFiles\W3SVC1", "*.log", $FLTA_FILES, True)

For $i = 0 To $aFiles[0]
    ; get file modification date
    $dLastModified = FileGetTime($aFiles[$i])
    $dLastModified = $dLastModified[0] & "/" & $dLastModified[1] & "/" & $dLastModified[2] & " " & $dLastModified[3] & ":" & $dLastModified[4] & ":" & $dLastModified[5]

    ; gets the date difference
    $iDateDiff = _DateDiff("D", $dLastModified, _NowCalc())


    If $iDateDiff >= 30 Then
        FileCopy($aFiles[$i], "D:\Backup\BackupTemp\")
    EndIf
Next

ShellExecuteWait("C:\Program Files (x86)\7-Zip\&z.exe", "a D:\Datacap\Taskmaster_logs\" & @MDAY & "." & @MON & "." & @YEAR & "-backup.zip D:\Datacap\Taskmaster_logs\tms.log")

 

1st script isn't working but 2nd one works... Many many thx...

 

Edited by epo
Update
Posted
  Quote

When trying the second suggestion, as an FYI, your For loop $i should begin counting from 1 not 0.

Yes I chg it, noted & thx...

Posted
  On 12/9/2015 at 4:12 PM, JLogan3o13 said:

When trying the second suggestion, as an FYI, your For loop $i should begin counting from 1 not 0.

Thanks! I wrote this directly on the forum reply input, that's why I wrote "test it first" :P

  On 12/9/2015 at 3:59 PM, epo said:

1st script isn't working but 2nd one works... Many many thx...

 

Nice to know that it was helpful :) 

My stuff

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...