Jump to content

FileExists and or IniRead not working for me..


Recommended Posts

So i just found AutoIt and have been working away at a simple test script as i learn. I decided to add an .ini file to make things easier. However even though i have verified that the ini file is named properly and placed in the correct directory when i use FileExists it won't find the file. I have tried using...

$iniFile = @scriptDir & "\default.ini"

I also have tried naming the ini file the same as the script and then..

$iniFile=stringleft(@ScriptName,stringlen(@scriptname)-4) & ".ini"

But no matter what i try it isn't finding the file. The ini file IS in the appropriate directory. and i do have #include <file.au3> so any help is appreciated.

Edited by hairyllama
Link to comment
Share on other sites

So i just found AutoIt and have been working away at a simple test script as i learn. I decided to add an .ini file to make things easier. However even though i have verified that the ini file is named properly and placed in the correct directory when i use FileExists it won't find the file. I have tried using...

$iniFile = @scriptDir & "/default.ini"

I also have tried naming the ini file the same as the script and then..

$iniFile=stringleft(@ScriptName,stringlen(@scriptname)-4) & ".ini"

But no matter what i try it isn't finding the file. The ini file IS in the appropriate directory. and i do have #include <file.au3> so any help is appreciated.

Hi hairyllama,

Is this really in your code?

$iniFile = @scriptDir & "/default.ini"   
                         ^

It should be a backslash "\"

A-Jay

Edited by ajag

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

Hi hairyllama,

Is this really in your code?

$iniFile = @scriptDir & "/default.ini"   
                         ^

It should be a backslash "\"

A-Jay

Oops yes i am using backslash just a typo when writing the first post! I shall edit it if i can.
Link to comment
Share on other sites

So it is better to post a snippet of your real code. It will help to see what's going wrong.

Did you try to type the full path like $IniFile = "D:\Test\default.ini"?

A-Jay

Edited by ajag

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

#include <file.au3>

if not FileExists("C:\default.ini") Then  
msgbox(0,"","The ini file could not be found at following location: root")  
exit  
EndIf

Just to test and make sure i wasn't insane. I did that, and yes the file default.ini is placed in the C:\ root. So i have no idea whats going on lol

Then you have to call a MD (hehe). Your example works fine for me...

A-Jay

Rule #1: Always do a backup         Rule #2: Always do a backup (backup of rule #1)

Link to comment
Share on other sites

Then you have to call a MD (hehe). Your example works fine for me...

A-Jay

Rats thats what i was afraid of. Guess something is screwed up with my system then. Laaaame ill try it on one of my other pc's. Thanks for the testing.

Link to comment
Share on other sites

#include <file.au3>

if not FileExists("C:\default.ini") Then  
msgbox(0,"","The ini file could not be found at following location: root")  
exit  
EndIf

Just to test and make sure i wasn't insane. I did that, and yes the file default.ini is placed in the C:\ root. So i have no idea whats going on lol

file.au3 doesn't need to be included for the FileExists function. If the file does exist at that location, then that script will just end without displaying a message, is that what's happening? Try this simpler rendition of that code if necessary.

If FileExists("C:\default.ini") Then MsgBox(0, "", "The file exists")
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

  • 1 year later...

It seems that @SCRIPTDIR includes a backslash when it's being run from root directory of a drive.

Try

MsgBox (0, "backslash or not?", @ScriptDir)

when run from the root of a drive [eg memory stick for test purposes], then from a subfolder.

This isn't in the documentation, which just says:

@ScriptDir - Directory containing the running script. (Result does not contain a trailing backslash)

William

Edited by saywell
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...