Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted (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 by Igzter
Posted

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.

Posted

  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'

Posted

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.

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...