amakrkr Posted June 11, 2010 Posted June 11, 2010 Hello, i have the following script to read "selected" folder and write every file into a TXT file. #include <Array.au3> #include <File.au3> $File = "c:\files\Filenames.dat" $Path = "c:\files\" $List = _FileListToArray($Path) _FileWriteFromArray($File, $List, 1) What I want to do now is a parameter or someting that will be sent to this script. Parameter should contain a user specified path which directory should be read. For example: c:\script.exe - c:\file\test\ I hope i made my self clear. Thanks for your help! PS making a GUI is not an option.
Juvigy Posted June 11, 2010 Posted June 11, 2010 Check out this topic: http://www.autoitscript.com/forum/index.php?showtopic=115656&st=0&p=807889&#entry807889 There i try to explain how this can be done.It is all in the helpfile - command line parameters.
amakrkr Posted June 13, 2010 Author Posted June 13, 2010 Hello again, i have encountered another problem. What i want to do with my script, is to read manually inputed path of a directory (Check out my script in 1st post). I have checked that thread and help file about Command Line Parameters but all i could get from it was: $CmdLine[0] equals... 2 $CmdLine[1] equals... param1 $CmdLine[2] equals... this is another param @ScriptName equals... myscript.au3 AutoIt3.exe myscript.au3 param1 "this is another param" So in my opinion you can't define for example $CmdLine[1] = $X and let $CmdLine[1] to get $X from script user? I want to make my script so, that user will define which directory will be read. Can anyone give me another hint? Thx for reading.
Igzter Posted June 13, 2010 Posted June 13, 2010 (edited) On 6/13/2010 at 2:23 PM, 'amakrkr said: Hello again, i have encountered another problem. What i want to do with my script, is to read manually inputed path of a directory (Check out my script in 1st post). I have checked that thread and help file about Command Line Parameters but all i could get from it was: $CmdLine[0] equals... 2 $CmdLine[1] equals... param1 $CmdLine[2] equals... this is another param @ScriptName equals... myscript.au3 AutoIt3.exe myscript.au3 param1 "this is another param" So in my opinion you can't define for example $CmdLine[1] = $X and let $CmdLine[1] to get $X from script user? I want to make my script so, that user will define which directory will be read. Can anyone give me another hint? Thx for reading. Actually you confuse me here - what you described above will do exactly what you ask for (if I am not misunderstanding you). $CmdLine is an array and $CmdLine[0] holds the number of parameters passed (in your case 2) and $CmdLine[1] and onwards holds whatever parameters where passed by the user. Ig Edited June 13, 2010 by Igzter
amakrkr Posted June 13, 2010 Author Posted June 13, 2010 Hello, thx for your replay. But i still dont understand how will program know what parameter to take. here is my code.... i know it has a major erros in it but please give me some advices. #include <Array.au3> #include <File.au3> $CmdLine[0] = 1 $CmdLine[1] $File = "c:\files\Filenames.dat" $Path = $CmdLine[1] $List = _FileListToArray($Path) _FileWriteFromArray($File, $List, 1) thank you.
kev51773 Posted June 13, 2010 Posted June 13, 2010 On 6/13/2010 at 4:31 PM, 'amakrkr said: Hello, thx for your replay. But i still dont understand how will program know what parameter to take. here is my code.... i know it has a major erros in it but please give me some advices. #include <Array.au3> #include <File.au3> $CmdLine[0] = 1 $CmdLine[1] $File = "c:\files\Filenames.dat" $Path = $CmdLine[1] $List = _FileListToArray($Path) _FileWriteFromArray($File, $List, 1) thank you. You're trying to set the command line parameters in the script. They already exist. If you ran this script - msgbox(0,$CmdLine[1],$Cmdline[2]) like this script.exe param1 param2 you would get a messagebox with a title of 'param1' and text of 'param2'
amakrkr Posted June 13, 2010 Author Posted June 13, 2010 problem is that my script doesnt work. File Filenames.dat is not created and i get error "you cannot assign values to a constant". I am just wondering what did i do wrong... Any help would be greatly appreciated.
kev51773 Posted June 13, 2010 Posted June 13, 2010 On 6/13/2010 at 7:53 PM, 'amakrkr said: problem is that my script doesnt work. File Filenames.dat is not created and i get error "you cannot assign values to a constant". I am just wondering what did i do wrong... Any help would be greatly appreciated. In which case you need to do something along the lines of... #include <Array.au3> #include <File.au3> $File = "c:\files\Filenames.dat" If $CmdLine[0] <> 1 Then MsgBox(0,"Error","You passed " & $CmdLine[0] & " parameters, only 1 was expected") Exit EndIf $Path = $CmdLine[1] $List = _FileListToArray($Path) _FileWriteFromArray($File, $List, 1) If your path has spaces it will need to be enclosed in ""
amakrkr Posted June 13, 2010 Author Posted June 13, 2010 @ kev51773 thx for quick answer mate! Finally i get it how it should work. Thx again.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now