Jump to content

Converting Batch File to AutoIt


Recommended Posts

I am just getting started with AutoIt so I hope this question is not too basic for those that have been using it for quit awhile.

I have a batch file that is used to execute an application that generates a series of text files. These text files are then 'zipped up' into one file using winzip. That file is then converted to an executable using Winzip's Self-Extractor program and then that file is FTP'ed to a remote site.

Below is the code for the main part of this process. What I need help with is how to convert these commands to autoit.

This batch file accepts as a parameter a folder location. Then it adds each file to one zip file and then it runs the self-extractor

Can anyone offer me some guidance on how I can do this?

------------------------------------------------------------------------------------------------

echo off

erase %1\csfiles.zip

"c:\Program Files\winzip\wzzip" %1\csfiles %1\csfil001.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil002.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil003.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil004.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil005.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil007.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil008.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil009.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil010.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil013.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil014.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil021.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil023.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil024.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil031.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil053.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil054.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil080.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil081.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil082.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles L:\MAGIC9\rs\csctlv94.mcf

"c:\Program Files\winzip\wzzip" -a %1\csfiles L:\MAGIC9\rs\csctlv94.mff

"C:\Program Files\WinZip Self-Extractor\WZIPSE32.EXE" -y -auto %1\csfiles -runasadmin -d c:\magic502\cs

------------------------------------------------------------------------------------------------------------------------------

Thanks in advance for any help.

Jim

Link to comment
Share on other sites

I am just getting started with AutoIt so I hope this question is not too basic for those that have been using it for quit awhile.

I have a batch file that is used to execute an application that generates a series of text files. These text files are then 'zipped up' into one file using winzip. That file is then converted to an executable using Winzip's Self-Extractor program and then that file is FTP'ed to a remote site.

Below is the code for the main part of this process. What I need help with is how to convert these commands to autoit.

This batch file accepts as a parameter a folder location. Then it adds each file to one zip file and then it runs the self-extractor

Can anyone offer me some guidance on how I can do this?

------------------------------------------------------------------------------------------------

echo off

erase %1\csfiles.zip

"c:\Program Files\winzip\wzzip" %1\csfiles %1\csfil001.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil002.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil003.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil004.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil005.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil007.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil008.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil009.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil010.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil013.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil014.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil021.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil023.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil024.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil031.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil053.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil054.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil080.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil081.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles %1\csfil082.dat

"c:\Program Files\winzip\wzzip" -a %1\csfiles L:\MAGIC9\rs\csctlv94.mcf

"c:\Program Files\winzip\wzzip" -a %1\csfiles L:\MAGIC9\rs\csctlv94.mff

"C:\Program Files\WinZip Self-Extractor\WZIPSE32.EXE" -y -auto %1\csfiles -runasadmin -d c:\magic502\cs

------------------------------------------------------------------------------------------------------------------------------

Thanks in advance for any help.

Jim

#include <Process.au3>
_RunDOS("echo off")
_RunDOS("erase %1\csfiles.zip")
.
.
.
_RunDOS("C:\Program Files\WinZip Self-Extractor\WZIPSE32.EXE -y -auto %1\csfiles -runasadmin -d c:\magic502\cs")

When the words fail... music speaks.

Link to comment
Share on other sites

you can specify the path with either an inputbox or by creating a GUI as well.

Another option would be to use _filelisttoarray and creating a loop to zip all the files.

there is a Au3Zip function written by eltorro that I use that works well. You do have to have a dll to do the actual zipping, but it is available on this thread.

Hopefully that will get you started.

Kerros===============================================================How to learn scripting: Figure out enough to be dangerous, then ask for assistance.

Link to comment
Share on other sites

#include <Process.au3>
_RunDOS("echo off")
_RunDOS("erase %1\csfiles.zip")
.
.
.
_RunDOS("C:\Program Files\WinZip Self-Extractor\WZIPSE32.EXE -y -auto %1\csfiles -runasadmin -d c:\magic502\cs")
This is no better (and makes less sense) than using the Run() command to just run the existing batch file.

Converting batch files is one of the first things I ever used AutoIt for!

Something like this should work:

$csFilesDir = ""

If @Compiled Then
    If $CMDLINE[0] = 0 Then
        MsgBox(48, @ScriptName, "No directory specified for csfiles" & @CRLF & @CRLF & "USAGE: " & @ScriptName & " ''csfilesdir''" & _
                @CRLF & @CRLF & "Where ''csfilesdir'' is the directory of csfiles to zip.")
    Else
        $csFilesDir = $CMDLINE[1]
    EndIf
Else
    $csFilesDir = FileSelectFolder("Select folder with csfiles to zip", "")
EndIf

Select
    Case $csFilesDir = ""
        ;If $csFilesDir = "" Then
        MsgBox(48, @ScriptName, "No directory specified for csfiles" & @LF & @LF & "Exiting...")
        Exit
        ;EndIf
    Case Not FileExists($csFilesDir) Or Not FileExists($csFilesDir & "\csfil*.dat")
        MsgBox(16, @ScriptName, "'' " & $csFilesDir & " ''" & @CRLF & @CRLF & "is not a valid folder for csfiles: no csfiles found" & @LF & @LF & "Exiting...")
        Exit
        Exit
    Case Else
        $csFilesDir = StringStripWS($csFilesDir, 3)
        _ZipCsFiles($csFilesDir)
EndSelect


Func _ZipCsFiles($csFilesDir)
    $csFilesDir = FileGetShortName($csFilesDir)
    If StringRight($csFilesDir, 1) = "\" Then $csFilesDir = StringTrimRight($csFilesDir, 1)

    $WinZipAddCmd = "c:\Program Files\winzip\wzzip -a"
    $ZipFileName = $csFilesDir & "\csfiles"
    $WinZipSfxCmd = "C:\Program Files\WinZip Self-Extractor\WZIPSE32.EXE -y -auto"
    

    If FileExists($ZipFileName & ".zip") Then FileDelete($ZipFileName & ".zip")
    MsgBox(0,"",$WinZipAddCmd & " " & $ZipFileName & " " & $csFilesDir & "\csfil001.dat")
    RunWait($WinZipAddCmd & " " & $ZipFileName & " " & $csFilesDir & "\csfil001.dat")
    RunWait($WinZipAddCmd & " " & $ZipFileName & " " & $csFilesDir & "\csfil002.dat")
    RunWait($WinZipAddCmd & " " & $ZipFileName & " " & $csFilesDir & "\csfil003.dat")
    ;etc
    ;etc
    RunWait($WinZipAddCmd & " " & $ZipFileName & " " & $csFilesDir & "\csfil082.dat")
    RunWait($WinZipAddCmd & " " & $ZipFileName & " " & "L:\MAGIC9\rs\csctlv94.mcf")
    RunWait($WinZipAddCmd & " " & $ZipFileName & " " & "L:\MAGIC9\rs\csctlv94.mff")
    RunWait($WinZipSfxCmd & " " & $ZipFileName & " " & "-runasadmin -d c:\magic502\cs")
EndFunc   ;==>_ZipCsFiles

Probably more complete than the guidelines you were looking for, but hey, I'm feeling genorous today :)

You might also want to look at storing your csfil*.dat list in an external file for easier maintenance ifyou ever want to modify the list of files to zip.

You would then use FileRead() or FileReadLine() functions to handle the data inside your script.

Link to comment
Share on other sites

how can i run Dos functions without using

;
#Include <Process.au3>
;

thanks!

Run(), as ResNullius already pointed out, is a native function not requiring any include files.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

  • 2 years later...

I am converting an old batch file to an autoit script and updating it to switch our toughbooks from one provider to another. I am running into difficulty with the if statement in the batch file to chage the firmware to AT&T. Setfirm and Setfirm2 are executables in the install directory. Any assistance would be much appreciated. The batch file is below:

ECHO Uninstalling current Connection Manager
rem Uninstall VZAccess Manager
IF EXIST "C:\Program Files\Verizon Wireless\VZAccess Manager\VZAccess Manager.exe" (
msiexec /x {A7CA6CC5-465B-41F8-96B5-F66BDF4482C7} /qn
)
ECHO Switching Firmware
if %1==/1 (
setfirm -switch:att
)
if %1==/2 (
setfirm2 -switch:att
)
IF ERRORLEVEL 1 EXIT 16
ECHO Installing ATT Connection Manager
cd wwan\att\acminst
..\..\..\gexec "ATTSetup.exe" /S /V"INSTALLDRIVERS="false" INSTALLBM=0 /qn"
IF ERRORLEVEL 1 EXIT 16
set ret=1

exit %ret%

Thank you,

Link to comment
Share on other sites

I am converting an old batch file to an autoit script and updating it to switch our toughbooks from one provider to another. I am running into difficulty with the if statement in the batch file to chage the firmware to AT&T. Setfirm and Setfirm2 are executables in the install directory. Any assistance would be much appreciated. The batch file is below:

ECHO Uninstalling current Connection Manager
rem Uninstall VZAccess Manager
IF EXIST "C:\Program Files\Verizon Wireless\VZAccess Manager\VZAccess Manager.exe" (
msiexec /x {A7CA6CC5-465B-41F8-96B5-F66BDF4482C7} /qn
)
ECHO Switching Firmware
if %1==/1 (
setfirm -switch:att
)
if %1==/2 (
setfirm2 -switch:att
)
IF ERRORLEVEL 1 EXIT 16
ECHO Installing ATT Connection Manager
cd wwan\att\acminst
..\..\..\gexec "ATTSetup.exe" /S /V"INSTALLDRIVERS="false" INSTALLBM=0 /qn"
IF ERRORLEVEL 1 EXIT 16
set ret=1

exit %ret%

Thank you,

You can try

Local $Return
ToolTip('Uninstalling current Connection Manager', -1, -1, ' ', 1, 4)
Sleep(500)

;rem Uninstall VZAccess Manager
If FileExists("C:\Program Files\Verizon Wireless\VZAccess Manager\VZAccess Manager.exe") Then
    RunWait('msiexec /x {A7CA6CC5-465B-41F8-96B5-F66BDF4482C7} /qn')
EndIf

ToolTip('Switching Firmware', -1, -1, ' ', 1, 4)
Sleep(500)

If $CmdLine[0] = '/1' Then $Return = RunWait('setfirm -switch:att')
If $CmdLine[0] = '/2' Then $Return = RunWait('setfirm2 -switch:att')
If $Return = 1 Then Exit 16

ToolTip('Installing ATT Connection Manager', -1, -1, ' ', 1, 4)
Sleep(500)

FileChangeDir('wwan\att\acminst')
$Return = ('..\..\..\gexec "ATTSetup.exe" /S /V"INSTALLDRIVERS="false" INSTALLBM=0 /qn"')
If $Return = 1 Then Exit 16
$Return = 1

ToolTip('Return Value = ' & $Return, -1, -1, ' ', 1, 4)
Sleep(3000)
Exit
Link to comment
Share on other sites

@TuxBird: Don't hijack old topics. It doesn't cost anything to start a new topic, and it makes searching for and finding answers easier.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
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
 Share

  • Recently Browsing   0 members

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