rinoatwisted

[Help] Convert batch script to Autoit

5 posts in this topic

#1 ·  Posted

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



#2 ·  Posted

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

 

1 person likes this

Regards,
 

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

#4 ·  Posted

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

#5 ·  Posted

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

    • 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.
    • fosil
      By fosil
      Hi everyone.

      I'm currently working a program that constantly prints out log files through "consolewrite" and the "#AutoIt3Wrapper_Change2CUI=y" wrapper.

      Part of this program requires me to run a batch script.

      My issue is the batch script launches from the same window as consolewrite. I need the batch file to be launched through a different window as currently this causes an issue with the logs (which need to be very precise) but also causes the batch file to produce some funny behavior...

      Does anyone know how I can force the file to run on a second DOS window?

      Thanks in advance!!!
       
      Edit: Im using the "run" command if that helps. I tried "shellexecute" but that seemed to not launch the batch scripts at all.
    • fopetesl
      By fopetesl
      I have several batch files, e.g.
      echo off echo !DT | ncat 192.168.1.6 80 > scan1.dta This data1.bat works as expected by saving data from !DT command.
      I have tried several variations from AutoIt
      ;  $DOS = RunWait(@ComSpec & " /k " & "ncat 192.168.1.6 80 <getdata >scan1.dta", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;  $DOS = Run(@ComSpec & " /k " & "ncat 192.168.1.6 80 <getdata >scan1.dta", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;  $DOS = Run(@ComSpec & " /c " & "echo ?DT | ncat 192.168.1.6 80 > scan1.dta & @CRLF", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)   $DOS = Run(@ComSpec & " /c " & "data1.bat & @CRLF", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) but none save the data to scan1.dta
      Run out of ideas so far...
       
    • StMaSi
      By StMaSi
      If I am using a RunWait command to launch a batch file from within an AutoIt script, how can I pass a variable to said batch file so that the batch file can utilize said variable like in a %var% format? Thank you in advance.
    • TXTechie
      By TXTechie
      I normally launch things silently, but now I want to launch a batch (.cmd) file and have it run as normal displaying it's standard output to the user. Whether I use ShellExecuteWait or RunWait, the command prompt window is displayed, but the output is blank (although I know that the batch file is processing normally because it also produces a log file).
      If this is because AutoIt is re-directing the standard I/O of the batch file/console window, is there a way I can bypass the I/O redirection?
      Thanks,
      TXTechie