Jump to content
Sign in to follow this  
Koenraad

Script problem

Recommended Posts

Koenraad

Hi there,

i've just started with all this and spending days trying to get into the beautiful art of scripting. But after hours of comparing examples, reading helpfiles and searching this forum (i really did!) and writing papers full of usefull info... i got stuck here. I tried using the converter to convert a vbs-script (if that is the right name) to AutoIt, but there seems to be a problem starting from the "DO"-command. Can someone have a look at it and give me a hint. I'm keen on learning but this is way over my head (i know, but it is such a challenge).

Other problem i have is to define a location in the script with a variable, but it needs a double \ (thats what it said on the internet)... eg: 'C:\\Scripts\\Test.txt'

btw: i try to copy a given file a number of times and rename those from an excel-list (it should keep copying until it meets a blank cell). This is what i came up with but it doesn't work:

Thanks in advance!

Noob, Koenraad :)

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

$strComputer = @ComputerName

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$colFiles = $objWMIService.ExecQuery("Select * From CIM_DataFile Where Name = 'C:\\Scripts\\Test.txt'")

$objExcel = ObjCreate("Excel.Application")

$objExcel.Visible = True

$objWorkbook = $objExcel.Workbooks.Open("C:\Scripts\Names.xls")

$intRow = 1

Do $objExcel.Cells($intRow, 1).Value = ""

Until $strNewName = $objExcel.Cells($intRow, 1).Value

For $objFile In $colFiles

$strCopy = "C:\Scripts\" & $strNewName

$objFile.Copy($strCopy)

Next $intRow = $intRow + 1

WinClose("Microsoft Excel - Book1"


greetzKoenraad

Share this post


Link to post
Share on other sites
James

You missed a bracket

$strComputer = @ComputerName

$strNewName = ""

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")

$colFiles = $objWMIService.ExecQuery("Select * From CIM_DataFile Where Name = 'C:\Scripts\Test.txt'")

$objExcel = ObjCreate("Excel.Application")
$objExcel.Visible = True 

$objWorkbook = $objExcel.Workbooks.Open("C:\Scripts\Names.xls")

$intRow = 1

Do 
    $objExcel.Cells($intRow, 1).Value = ""
Until $strNewName = $objExcel.Cells($intRow, 1).Value

For $objFile In $colFiles
$strCopy = "C:\Scripts\" & $strNewName
$objFile.Copy($strCopy)
$intRow = $intRow + 1
Next

WinClose("Microsoft Excel - Book1")

I got that bit. Can you post the other files?

You dont need \\ I havent seen them used in normal files.

Edited by Secure_ICT

Share this post


Link to post
Share on other sites
Koenraad

Hi,

here is the complete file. I wrote some comments to go with it (it's actually supposed to be in flemish, since primary school kids don't speak english)

hope you like the GUI. Looks basic, but took me hours. (the "..." or browse button doesn't work properly if you don't click on the rightbottom, which is pretty weird. I think it has something to do with the grouping).

I'm curious to see what i did "wrong" (read "didn't know" :) )

Thanks

Koenraad

Banana.au3


greetzKoenraad

Share this post


Link to post
Share on other sites
James

Heh. First error when running.

$Set $objWMIService
        ~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(90,81) : WARNING: $GetObject: possibly used before declaration.
        $Set $objWMIService = $GetObject("winmgmts:\\" & $strComputer & "\root\cimv2")
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(92,8) : ERROR: syntax error
        $Set $colFiles
        ~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(93,3) : ERROR: syntax error
        $ExecQuery
        ^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(95,8) : ERROR: syntax error
        $Set $objExcel
        ~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(95,54) : WARNING: $CreateObject: possibly used before declaration.
        $Set $objExcel = $CreateObject("Excel.Application")
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(96,28) : WARNING: $True: possibly used before declaration.
        $objExcel.Visible = $True
        ~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(96,28) : WARNING: $objExcel possibly not declared/created yet
        $objExcel.Visible = $True
        ~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(98,8) : ERROR: syntax error
        $Set $objWorkbook
        ~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(102,6) : ERROR: syntax error
        Do Until
        ~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(105,14) : ERROR: syntax error
            For $Each $objFile
            ~~~~~~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(107,27) : WARNING: $objFile: possibly used before declaration.
            $objFile.Copy($strCopy)
            ~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(108,4) : ERROR: missing EndSelect.
            Next
            ^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(102,3) : REF: missing EndSelect.
        Do
        ^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(108,4) : ERROR: missing Wend.
            Next
            ^
C:\Documents and Settings\Keith\Local Settings\Temporary Internet Files\Content.IE5\RD4ADPH0\Banana[1].au3(60,10) : REF: missing Wend.
   Select
~~~~~~~~~^

Share this post


Link to post
Share on other sites
Koenraad

mm

not what i expected. I had it converted b the scriptomatic into AutoIt-code and tweaked some things. I looked up the different functions eg Do Until etc.

But where do i go from here? Everything starting from the last "case" doesn't make any sense to me. For instance what is $objExcel.Cells($intRow,1).Value = ""?? With the dots between it.

Maybe i can tell it to open up notepad and write the vbs-script in it and save it as a vbs. I read somewhere on this forum that one should be able to do just about anything possible with vbs with AuotIt. But this might be a work around for me.

What do you reckon?


greetzKoenraad

Share this post


Link to post
Share on other sites
Shadymilkman

Im not quite sure what you're trying to do here, but it looks like your wanting to copy files to a different place and rename them according to text in an Excel file. The reason why things weren't wanting to be clicked on was because you had the size of one of your labels WAY to large, covering most of the window. I've been working on the file and have come close to what I believe you wish to do. Instead of reading from an Excel file you should make it a .ini file, it would be easier to accomplish. Anyhow here is what I have come up with.....

Sorry, I would continue to work on the file but im gettin sleepy. I hope this sets you in the right direction :)

Banana.au3

Share this post


Link to post
Share on other sites
Koenraad

Thansk for fixing the browse-button thing. It didn't occur to me that that might have been the case.

I inserted the messagebox, just to see if i could get an output when pressing the button. Because that's the only output thing i learned from the tutorial. (So, yo can get rid of the Msgbox if that makes it any easier). So, i thought i could make it without relying on the window-names, to make it more reliable.

I analysed lots of other scripts (eg the UniExtractor) and he used a ini-file as well, but i don't know what it does or how to use it. I looked it up on the internet. I suppose you use it to store all the new names retrieved from the excel-file (in the GUI i made clear to the user that those names have to be in colom1, so you can be sure of that. I thinks that makes it easier to program, doesn't it?)

Btw: how did you get the path into the inputbox, i always got a number there. I can't see any changes...

(sorry for all those questions, i just want to know 'cause thats the way to learn it :) )

SO: when you press the button, it opens up excel. The user selects the first cell, which is being copied to the clipboard and then the next one...,right?

Case $msg = $doe

$Clipboard = ClipGet()

WinActivate("Microsoft Excel","Excel")

MsgBox(0,"","Select the first cell and push 'Ok'")

For $j = 1 To 2

Send("^{c}")

If $Clipboard == "" Then

MsgBox(0,"",$Clipboard)

IniWrite("Data.ini","Names",$Clipboard,"")

Send("{Down}")

EndIf

Next

;FileCopy($inputi,$inputi3 & $NewName[$i][0])


greetzKoenraad

Share this post


Link to post
Share on other sites
Shadymilkman

The number you were getting from the inputbox was the ID number of the box, not the contents.

Thats why you use this

$inputi = GUICtrlRead($input)
$inputi2 = GUICtrlRead($input2)
$inputi3 = GUICtrlRead($input3)

This would be a lot easier if you just skipped the Excel file and went straight to a .ini file. The method I was trying to use here was just to extract the data from the excel file and it was being stubborn. Where are you getting the names into the Excel file from? Maybe a user? If so you can make a separate program, or add a function into your's that takes the names instead.

Share this post


Link to post
Share on other sites
Gif

a vbs-script (if that is the right name)

in vbs -S stands for script so it's wrong :)

Edited by c4nm7

Share this post


Link to post
Share on other sites
Koenraad

This would be a lot easier if you just skipped the Excel file and went straight to a .ini file. The method I was trying to use here was just to extract the data from the excel file and it was being stubborn. Where are you getting the names into the Excel file from? Maybe a user? If so you can make a separate program, or add a function into your's that takes the names instead.

The names are in the excel file, cause it is a file that is being used for other purposes as well (it includes all the names of the children). What you suggested sounds like a superb idea, but its all way over my head. So, now i'm trying to make AutoIt send the whole text of the script and save is as a vb-script (thanks clearing that up, c4nm7). Then run it. 'cause it works as a vb-scriptfile. But if you have some good suggestions on how to extract the data from the excel-file and put it in an .ini, plz let me know. I'm willing to give that a try. But i can't understand the code you wrote earlier, it looks simple. i'm not familiar with the functions and the special symbols (i looked them up, but i can't "see" it as a whole of what it is actually doing step by step)...

Edited by Koenraad

greetzKoenraad

Share this post


Link to post
Share on other sites
Lemmens Peter

Beste Koenraad,

If I understand correctly, you want to copy 1 file x times (each time with a different name)

1.) Why don't you copy (Ctrl-C) the filenames from Excell and paste (Ctrl-V) them into a Notepad. Be carefull the full path needs to be in there (Good example : c:\Program Files\ItsMe\My documents\First_File.txt) not only the filename (Bad example : First_File.txt)

Save this notepad in the same directory as your script and call it "FileWithNewFileNames.txt".

So "FileWithNewFileNames.txt" contains the list of filenames (with paths) you want to use as destination.

2.) Modify the script and replace the value of $File_To_Copy with the name of the file you want to copy x times. (once again don't forget : full path)

3.) Modify also the value of $What_To_Do to the value you want (see comment added below the $What_To_Do value)

4.) Run the script.

I hope this will be of use,

Peter

$File_To_Copy = "c:\Temp\FileToCopy.txt"
$File_With_New_FileNames = @ScriptDir & "\FileWithNewFileNames.txt"

$What_To_Do = 1 + 8
; 0 = (default) do not overwrite existing files
; 1 = overwrite existing files
; 8 = Create destination directory structure if it doesn't exist (See Remarks).


$file = FileOpen($File_With_New_FileNames, 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file : " & $File_With_New_FileNames)
    Exit
EndIf
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
;   MsgBox(0, "Line read:", $line)
    FileCopy ( $File_To_Copy , $line , $What_To_Do)
Wend
FileClose($file)
Edited by Lemmens Peter

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
Sign in to follow this  

×