Jump to content

Unable to use a variable as part of directory path


Recommended Posts

Hi,

I've been using AutoIt for around a month and have found it very useful :) Have been able to automate most of the tasks I wanted to.

I have encountered a hiccup and not sure how to get this working.

Suppose there is a folder by name - ConfigurationFolder - in the same directory where my autoscript is present. Inside this folder, there is a file, logfile.txt.

There is an excel sheet which has the data regarding the folder name (ConfigurationFolder) and the file name (logfile.txt). I have an autoit script which reads the excel, captures this information in two variables... say $folder has the folder name and $file has the file name.

Something like... $folder = ConfigurationFolder

$file = logfile.txt

I would be using these two variables to check if the directory exists and check is the file exists. Then make use of the file.

For that, first I need to be able to use the variables as part of the directory path.

Suppose my autoit script is in the location - C:\Users\script.au3

When I try the below autoit script to assign the full path in the variable - $Directory, it doesn't work.

$Directory = @ScriptDir & "\$folder\$file"

"\$folder\$file" remains as it is, i.e., it gets translated to C:\Users\$folder\$file and not C:\Users\ConfigurationFolder\logfile.txt

Can someone please help me out here?

Cheers,

Ganesh

Link to comment
Share on other sites

There is also a second method.

See this script.

$folder = "myFolder"
$file = "myFile"

$Directory1 = @ScriptDir & "" & $folder & "" & $file

Opt("ExpandVarStrings", 1)
$Directory2 = "@ScriptDir@$folder$$file$"

MsgBox(262144,"",$Directory1 &@LF & $Directory2,0)

App: Au3toCmd              UDF: _SingleScript()                             

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