Jump to content
rinoatwisted

[Help] Convert batch script to Autoit

Recommended Posts

rinoatwisted

Hello guys,

im just started in programming and all..

and i wanted to learn autoscript to.

Was wondering if any can convert my  one-liner batch script to an autoit script -

FOR /F %%i IN (names.txt) DO @copy system.act %%i.act

 

So what this does is open and read the file "names.txt" incrementally, and copy a certain file named "system.act" and rename it to each name that is listed on "names.txt"

 

So im trying this on autoit but no idea how to start file manipulation and do command -

 

#include <File.au3>

$file = "c:\names.txt"
FileOpen($file, 0)

For $i = 1 to _FileCountLines($file)
    $line = FileReadLine($file, $i)

 

Can anyone help me or guide me on how to continue this to get the result that i want..:)?

Thanks

Share this post


Link to post
Share on other sites
VIP

You can try:

#NoTrayIcon
#include <MsgBoxConstants.au3>

Global Const $sFileListName = @HomeDrive & "\names.txt" ; path of file list name
Global Const $iFile = @HomeDrive & "\system.act" ; Path to file want copy and rename
Global Const $iDirCopyTo = @HomeDrive
Global Const $iExtFile = ".act"
Global Const $sOverWrite = True

If Not FileExists($sFileListName) Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Error 1", "The file doesn't exist: " & @CRLF & $sFileListName)
If Not FileExists($iFile) Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Error 2", "The file doesn't exist: " & @CRLF & $iFile)

Global $iNewPath, $sListName = FileReadToArray($sFileListName) ; Read list name to array by line

For $i = 0 To UBound($sListName) - 1
    $iNewPath = $iDirCopyTo & "\" & $sListName[$i] & $iExtFile
    ConsoleWrite("Copy (" & $i & ") to :> " & $iNewPath & "  :>: " & (FileCopy($iFile, $iNewPath, $sOverWrite) ? "OK" : "Error") & @CRLF)
Next

 

  • Like 1

Regards,
 

Share this post


Link to post
Share on other sites
rinoatwisted

Holy ****

Its perfect.

I like to thank you that you make an effort to actually make me a whole script..

and i learned a lot from your script. 

the real reason why i want it on autoit is that, the batch file that i made does not work if there is a  sp. charcter on the file name..

and i just tried this code and WOW.. thank you again from the bottom of my hearts..this will save me a countless hours..

 

thanks

Share this post


Link to post
Share on other sites
rinoatwisted

One question though, the file being renamed has a space between the last letter and the .act extension.

for example "nextserver .act" is should be "nextserver.act" only no space..:)

 

can i ask where to edit it? or remove the space?

Share this post


Link to post
Share on other sites
VIP

Try search before ask!
use StringStripWS() or StringReplace()

#NoTrayIcon
#include <MsgBoxConstants.au3>

Global Const $sFileListName = @HomeDrive & "\names.txt" ; path of file list name
Global Const $iFile = @HomeDrive & "\system.act" ; Path to file want copy and rename
Global Const $iDirCopyTo = @HomeDrive
Global Const $iExtFile = ".act"
Global Const $sOverWrite = True

If Not FileExists($sFileListName) Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Error 1", "The file doesn't exist: " & @CRLF & $sFileListName)
If Not FileExists($iFile) Then Exit MsgBox($MB_ICONERROR + $MB_TOPMOST, "Error 2", "The file doesn't exist: " & @CRLF & $iFile)

Global $iNewPath, $sListName = FileReadToArray($sFileListName) ; Read list name to array by line

For $i = 0 To UBound($sListName) - 1
;~     $iNewPath = $iDirCopyTo & "\" & $sListName[$i] & $iExtFile
    $iNewPath = $iDirCopyTo & "\" & StringStripWS($sListName[$i] & $iExtFile, 8) ; No space on file name
;~  $iNewPath = $iDirCopyTo & "\" & StringReplace($sListName[$i] & $iExtFile, " .", ".") ; No space on file name
    ConsoleWrite("Copy (" & $i & ") to :> " & $iNewPath & "  :>: " & (FileCopy($iFile, $iNewPath, $sOverWrite) ? "OK" : "Error") & @CRLF)
Next

 


Regards,
 

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

    • VollachR
      By VollachR
      I'm quite new to AutoIT and I have a very big batch file that I'm trying to completely re-write in Autoit, so far it's been going well but I got stuck with a certain part, hope someone can help.
      Here's the part of the batch script I'm currently stuck re-creating in AutoIT:
          :BeginLangMenu     if "%OptNum%" gtr "0" goto ShowLangMenu          ::Next Section code based on code supplied by Aacini from stackoverflow.com     :DefineLangMenu     for /L %%D in (1,1,99) do (        if exist Common\Settings\Data%%D.ini for /F "eol=# tokens=1,2 delims==" %%a in (Common\Settings\Data%%D.ini) do (                set line=%%a           if "!line:~2,5!" neq "clude" (              REM Define "normal" variables, i.e. Compressor, Method, etc.              set %%a=           ) else if "!line:~7!" neq "" (                   REM Define the base array elements, i.e. D1IncludeAR=%%b, D1ExcludeAR=%%b, ...              set D%%D%%a=%%b                   REM Set Show?? array elements with value equal 1, i.e. ShowAR=1, ...              REM when anyone of DiInclude?? or DiExclude?? corresponding elements was given              if defined D%%D%%a set Show!line:~7!=1                )        )     )          REM Define a list of language abbreviations, i.e. "langs=AR CZ DE ..."     REM and the corresponding language names array, i.e. lang[AR]=Arabic, ...     REM At same time, calculate original OptNum          for %%a in ("AR=Arabic" "CZ=Czech" "DE=German" "EN=English" "ES=Spanish" "ESMX=Spanish(Mexico)"                 "FR=French" "HU=Hungarian" "IT=Italian" "JP=Japanese" "KR=Korean" "PL=Polish"                 "PR=Portuguese" "PRBR=Portuguese(Brazil)" "RU=Russian" "ZH=Chinese") do (        for /F "tokens=1,2 delims==" %%b in (%%a) do (           set "langs=!langs! %%b"           set "lang[%%b]=%%c"           set /A "OptNum+=Show%%b"             )     )          ::NEXT 2 SECTIONS DISPLAYS THE LANGUAGE SELECTION MENU IF APPLICABLE     :ShowLangMenu     set /a step=%step%+1     :LangMenu     if "%OptNum%"=="0" Goto checksplit     echo %TIME:~0,2%:%TIME:~3,2%:%TIME:~6,2% - Showing Language Selection Menu >> "%workdir%Conversion.log"     REM Show the language menu     set #=0     for %%a in (%langs%) do (        if defined Show%%a (           set /A #+=1     rem       echo [!#!] !lang[%%a]!           echo !lang[%%a]! >> %b2eincfilepath%\Lang.txt           set "option[!#!]=%%a"         )     )               %MYFILES1%\DROPDOWNBOX.exe /F:"%b2eincfilepath%\Lang.txt" "Choose Which Language to Compress" "STEP %step%: Language Selection"  /W:280 /RI /C:13 >nul > %b2eincfilepath%\LangAnswer.txt     if %ERRORLEVEL% EQU 0 del %b2eincfilepath%\LangAnswer.txt     if exist %b2eincfilepath%\LangAnswer.txt set /p "SelectLang="<%b2eincfilepath%\LangAnswer.txt     if not defined SelectLang goto LangError     if %SelectLang%==Arabic Set LangOpt=AR     if %SelectLang%==Czech set LangOpt=CZ     if %SelectLang%==German set LangOpt=DE     if %SelectLang%==English set LangOpt=EN     if %SelectLang%==Spanish set LangOpt=ES     if %SelectLang%==Spanish(Mexico) set LangOpt=ESMX     if %SelectLang%==French set LangOpt=FR     if %SelectLang%==Hungarian set LangOpt=HU     if %SelectLang%==Italian set LangOpt=IT     if %SelectLang%==Japanese set LangOpt=JP     if %SelectLang%==Korean set LangOpt=KR     if %SelectLang%==Polish set LangOpt=PL     if %SelectLang%==Portuguese set LangOpt=PR     if %SelectLang%==Portuguese(Brazil) set LangOpt=PRBR     if %SelectLang%==Russian set LangOpt=RU     if %SelectLang%==Chinese set LangOpt=ZH     if defined SelectLang Goto LangSet          ::SETS THE LANGUAGE SELECTION ACCORDING TO USER INPUT IN LANGUAGE MENU     :LangSet     set "LangIs=%LangOpt%"  
      Basically, here's what I need to do:
       Read from specific section of INI file but ONLY the Keys that have a Value. OR: A way to remove the keys without the values from the Array created by IniReadSection. A way to then take these stored values, and create a list of Languages based last 2-4 characters of the Key names. At this point, that said list is shown to user in DropDown box, after user make selection I need a way to move the Value of the Key related to the selected Language to a Variable, and ONLY the value for that specific Language. That's it basically, the rest is more or less Variable manipulation which isn't a problem.
      A little Example:
      My INI file have a Section like this:
      [LangInclude] IncludeAR=a IncludeCZ= IncludeDE=b IncludeEN= IncludeES=c IncludeESMX= IncludeFR= IncludeHU=d IncludeIT= IncludeJP= IncludeKR=e IncludePL= IncludePR= IncludePRBR= IncludeRU= IncludeZH= I need to get Only the keys that are set, in this case: IncludeAR, IncludeDE, IncludeES, IncludeHU & IncludeKR.
      I then need to convert these to a list of languages, in this example it will be (Arabic, German, Spanish, Hungarian, Korean).
      That list will be turned to DropDown selection, that I can do easily once I get the list correctly.
      After the user Selected, let us say for the example purpose Spanish, I need the Value of IncludeES to be moved into a Variable, like this: $Var=c
      I hope somebody can help me because I'm stuck after Importing the INI section with IniReadSection, everything I tried so far failed, the best I managed to do is Sort the array to have all the keys with values either at the first rows or last rows.
      I need some ideas.
      Help appreciated.
      Thanks
       
    • TheSaint
      By TheSaint
      TeraCopy Timer - A program of mine, front end really, that I have been working on (on & off) for some time, but not shared here before, that I recall. Third party program TeraCopy is required.
      Many of you will be familiar with TeraCopy, and it has been discussed here at AF on several occasions, in various sub forums, including Chat.
      BE ADVISED - I still use an older version of TeraCopy (v2.27), a goody but an oldy, so have only tested my program with that. It may work with the newer v3.xx, or may be easily adjusted to do so, but I have not yet gone that route. Likewise, I only use it with Win 7 and Win XP, but I don't imagine there should be any issues with newer Windows. Add to that, my program being devised and created in AutoIt v3.3.0.0.
      So what is TeraCopy Timer and why might you need it?
      --------------------------------------------------------------------------------------
      Those familiar with TeraCopy use, know you can run multiple copy or move jobs either simultaneously or concurrently (one immediately after another has finished). With the free version at least, you have no control over precise order or timing, and no way to deal (without manual interaction) with the pesky Thumbs.db files in Win XP. TeraCopy Timer allows you to do all those things, and in a batch fashion.
      --------------------------------------------------------------------------------------
      Some screenshots and brief explanation
      Main Window
      Minimalist Window
      This new WAIT feature is the simplest and best way to use the program generally (in my view) ... but check out the following, as it is not always the case.
      Advanced Delay Window
      WARNING - It should go without saying, that you take all the usual precautions. For instance, don't use move with the only copy you have of precious files. BACKUP BACKUP BACKUP! Don't hold me liable for anything, except for being a nice guy who likes to share.
      TeraCopy Timer v2.8.zip  (see detail at Post #34)
      Enjoy!
      OLDER DOWNLOADS
      P.S. I am not affiliated in any way with those who created and provide the excellent third party program - TeraCopy.
    • rootx
      By rootx
      Hi, I need to convert this batch, I follow microsoft specs here https://technet.microsoft.com/en-us/library/bb491005.aspx
      Ex:
      start /b 1.exe "path\2.exe"
      start /b mypgrcommand
      start /b /wait 3.exe "path\4_.exe"
      taskkill /F /IM 5.exe
      Somethings like this...
      RunWait( @COMSPEC & " /c start /b 1.exe 'path\2.exe' start /b mypgrcommand start /b /wait 3.exe 'path\4_.exe' taskkill /F /IM 5.exe", "", @SW_SHOW ) Thx
    • Eggsplorer
      By Eggsplorer
      Hi,
      Ich hab ein Script für Windows Updates, dass nach dem OOBE aufgerufen werden soll. Run/RunOnce ist daher nicht möglich.
      Stattdessen möchte ich das Script in den Autostart schreiben lasse. Wenn die OOBE beendet wird und der Administrator angemeldet wird, soll das Update-Script einmalig aufgerufen werden und sich anschl. selbst löschen.
      Lang rede, kurzer Sinn:
      Wie kann ich folgendes Script in den Autostart schreiben?
      RunWait(@ComSpec & " /c " & "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\UA\Scripts\win-updates.ps1 -MaxUpdatesPerCycle 100 -RestartRequired 1", "") Ich würde ungern eine BAT oder EXE reinkopieren, da ich es unsauber finde. Die müsste ja auch zusätzlich irgendwo liegen.
      Danke
      Eggsplorer
    • ur
      By ur
      I am running the tomcat batch file through autoit   and need to wait until the below line I get in console output.

      But when I am trying to read the console output using the ProcessEx UDF, I am getting only the partial output.
      So, can you please suggest how to handle this.
×