epo

Help me to translate bat file to au3 file

9 posts in this topic

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...

Share this post


Link to post
Share on other sites



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( ͡° ͜ʖ ͡°)

Share this post


Link to post
Share on other sites

@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?

 


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path Random stuff Super Mario beep sound your ears will hurt

 

Share this post


Link to post
Share on other sites

@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)...

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

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


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

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...

Share this post


Link to post
Share on other sites

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

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

 

Nice to know that it was helpful :) 


My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path Random stuff Super Mario beep sound your ears will hurt

 

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