Jump to content

Simple Script Need Help


Recommended Posts

Ok I have made a script to download a picture from the net to C:\Kitten.jpg but what I really want is for the file to be downloaded to the dir that the script has be run from.

The picture I have it downloading is just there to expand on with further idea in the future.Check it out though its pretty funny.

How would I go about doing this ?

URLDownloadToFile("http://www.pix.org.za/_tn/std/bizarre/kitten-in-beer-glass-ANON.jpg", "C:\Kitten.jpg")

I have been messing with both these ideas but cannot get either to work

Idea 1

....................................................................................................

...................

URLDownloadToFile("http://www.pix.org.za/_tn/std/bizarre/kitten-in-beer-glass-ANON.jpg", ""@ScriptFullPath")

....................................................................................................

...................

Idea 2

If FileExists(C:\Kitten.jpg) Then

FileCopy(C:\Kitten.jpg, "@ScriptFullPath*.*")

Else

FileCopy(C:\Kitten.jpg, "@ScriptFullPath*.*")

EndIf

....................................................................................................

...................

Can anyone help me with the right code ?

Tnx

Nova

Edited by nova
Link to comment
Share on other sites

Ok that worked perfectly tnx ,but how do I now make that file open from the script dir ?

Im kinda lost because im not use to the macros !

Edited by nova
Link to comment
Share on other sites

...how do I now make that file open from the script dir ?

You want to open a picture? Unless you're putting it into a GUI dialog box, AutoIt can't actually display the picture. So you'd need to call another application (like mspaint.exe, the PhotoEditor that comes with office, or some other app.) Here's an example using paint:

Run(@ComSpec, " /c mspaint.exe My_Picture.jpg")

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Ok I dont really understand the last command you posted

I have tryed

Run(@ComSpec, " /c mspaint.exe Kitten.jpg")

Run(@ComSpec, " /c mspaint.exe @ScriptDir/Kitten.jpg")

Run(@ComSpec, " /c mspaint.exe @ScriptDir Kitten.jpg")

What am I doing wrong ? :D

Edited:Just saw above post tnx but I want it to open with ms paint so splashimageon isnt an option.

Edited by nova
Link to comment
Share on other sites

Er, you forget

Actually, I didn't know you could do that. It isn't in the documentation for SplashTextOn, so I assumed the 2nd paramater had to be text.

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

What am I doing wrong ?

Unless your picture is in the same directory as your Command Interperter, the first method will fail. And you aren't properly joining the strings in your last two examples. Remember, that @ScriptDir is nothing more than a string of the script's directory, so you have to properly join them wtih then & character. Like this:

Run(@ComSpec & " /c mspaint.exe " & @ScriptDir & "\My_Picture.jpg")

Don't forget the leading backslash, since @ScriptDir does not contain that on the end.

Edit: Also, you'll have to use double quotes arround the path if the path to your picture contains any spaces.

Edit2: See also the post below this one. I missed the fact that there were 2 arguments to the incorrect code.

Edited to correct a typo

Edited by pekster

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Run(@ComSpec, " /c mspaint.exe @ScriptDir/Kitten.jpg")

What am I doing wrong ? :D

Because you're giving the Run the wrong command line parameters.

Run ( "filename" [, "workingdir" [, flag]] )

This is from the helpfile and means that you need to pass the command you want to run as the first argument. The second and third arguments are optional and are seperated by the comma character: ,

So your command tells Run:

1. Go to the directory " /c mspaint.exe @ScriptDir/Kitten.jpg"

2. execute the command stored in the macro @ComSpec

Is Kitten.jpg a directory? I'm pretty sure it isn't, so Run will fail at that point.

You have to combine the two strings @ComSpec and " /c mspaint.exe @ScriptDir/Kitten.jpg" to make it work. Use & for combining strings.

Link to comment
Share on other sites

Ok its still not working.

URLDownloadToFile("http://www.pix.org.za/_tn/std/bizarre/kitten-in-beer-glass-ANON.jpg", @ScriptDir & "\Kitten.jpg")

Run(@ComSpec & " /c mspaint.exe " & @ScriptDir & "\Kitten.jpg")

When I run the program from inside a folder the image download properly to the folder and is called Kitten.jpg but then a cmd window opens up and I get an mspaint error msg saying c:/Documents.bmp was not found

The code dosent ask to open a file from the c:/ called Documents.bmp

so why is it doing so ?

Edited:Sugi u posted while I was posting so this reply is to peksters post.

I have read ur post and while I am sure what ur telling me to do is right I dont understand it.Im still new to autoit v3 so macros are still beyond me at this point,I need more time to pratice using them.

Edited by nova
Link to comment
Share on other sites

Ok its still not working.

URLDownloadToFile("http://www.pix.org.za/_tn/std/bizarre/kitten-in-beer-glass-ANON.jpg", @ScriptDir & "\Kitten.jpg")

Run(@ComSpec & " /c mspaint.exe " & @ScriptDir & "\Kitten.jpg")

When I run the program from inside a folder the image download properly to the folder and is called Kitten.jpg but then a cmd window opens up and I get an mspaint error msg saying c:/Documents.bmp was not found

The code dosent ask to open a file from the c:/ called Documents.bmp

so why is it doing so ?

If the path (@ScriptDir) contains spaces the command will fail.

You have to use this:

Run(@ComSpec & ' /c mspaint.exe "' & @ScriptDir & '\Kitten.jpg"')
Link to comment
Share on other sites

Excellent finally It works thank you SlimShady and tnx to everyone that posted trying to help me.

Srry I confussed such a simple command so much,and proberly anoyed u all in the process.

Tnx again

Nova

Link to comment
Share on other sites

Excellent finally It works thank you SlimShady and tnx to everyone that posted trying to help me.

Srry I confussed such a simple command so much,and proberly anoyed u all in the process.

Tnx again

Nova

You didn't annoy me.

All new things are difficult at the start.

When you practice, study many scripts you'll get used to it.

And everything will work out fine.

Many things I learned from the help file. You should really start there.

If you're really, really stuck then you should post a question.

(It's only an advice. I don't command anyone.)

Link to comment
Share on other sites

If the path (@ScriptDir) contains spaces the command will fail.

Yea, I forgot this and added it in as an Edit (prehaps I should have made a new post, but oh well.) It's easy to forget something unless you've actually written and tested it yourself :D

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

Unless your picture is in the same directory as your Command Interperter, the first method will fail. And you aren't properly joining the strings in your last two examples. Remember, that @ScriptDir is nothing more than a string of the script's directory, so you have to properly join them wtih then & character. Like this:

Run(@ComSpec & " /c mspaint.exe " & @ScriptDir & "\My_Picture.jpg")

Don't forget the leading backslash, since @ScriptDir does not contain that on the end.

Edit: Also, you'll have to use double quotes arround the path if the path to your picture contains any spaces.

Edit2: See also the post below this one. I missed the fact that there were 2 arguments to the incorrect code.

Edited to correct a typo

I hate double quotes but love

FileGetShortName ( "file" )

Rick

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