Sign in to follow this  
Followers 0
Khryus

This work just in part, why?

20 posts in this topic

I have made a script to check wheter there's or there's not a "config.ini" file in the directory where the script is, but it only prompts a message box when it's missing.

Why?

;look for the config.ini file
    Local $configFile = FileFindFirstFile("config.ini")
    If $configFile = -1 Then
        MsgBox(48, "Error", "Error: unable to find config.ini file.")
        Exit
    Else
        MsgBox(64, "Info", "Found config. file")
        Exit
    EndIf

"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I have made a script to check wheter there's or there's not a "config.ini" file in the directory where the script is, but it only prompts a message box when it's missing.

Why?

;look for the config.ini file
    Local $configFile = FileFindFirstFile("config.ini")
    If $configFile = -1 Then
        MsgBox(48, "Error", "Error: unable to find config.ini file.")
        Exit
    Else
        MsgBox(64, "Info", "Found config. file")
        Exit
    EndIf

Remove the Exit after the first MsgBox

Edit - loose both Exits, they are not needed

Edited by BigDod


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

megablox,

Do not use FileFindFirstFile (which returns a search handle) for this - use FileExists (which returns 0/1): :)

;look for the config.ini file
If FileExists("config.ini") = 0 Then
    MsgBox(48, "Error", "Error: unable to find config.ini file.")
    Exit
Else
    MsgBox(64, "Info", "Found config. file")
    Exit
EndIf

FileFindFirstFile is only used when you are going to search for many files with FileFindNextFile which needs that handle as a parameter. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks both, but the second msgbox doesnt appear with each solution :


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

maby

Local $configFile = FileFindFirstFile("config.ini")
If @error Then
    MsgBox(48, "Error", "Error: unable to find config.ini file.")
Else
    MsgBox(64, "Info", "Found config. file")
EndIf
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

bogQ, doesn't work, tried this:

;look for the config.ini file
    Local $configFile = FileExists("config.ini")
    If Not @error Then
        MsgBox(64, "info", "Found config.ini file")
    ElseIf @error Then
        MsgBox(48, "info", "Error: Unable to find config.ini file.")
    EndIf

with the config file, it runs and does nothing. without, it prompts the msgbox.


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

where i wroted If Not @error

im preaty shure i wroted If @error Then

and probably FileExsist is better solution for you

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Still the same thing.


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Try it like this,

Local $configFile = FileExists("config.ini")
If $configFile Then
    MsgBox(64, "info", "Found config.ini file")
Else
    MsgBox(48, "info", "Error: Unable to find config.ini file.")
EndIf

edit: I forgot to say this - If you don't need the $configFile variable, delete the first two lines and replace with If FileExists("config.ini") Then.

another edit: Oops, this code is pretty much the same as M23's..

Edited by somdcomputerguy

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

Share this post


Link to post
Share on other sites

Thanks both, but the second msgbox doesnt appear with each solution :

Both options work here.


Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

megablox,

My version works for me - or I would not have posted it. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

and for me all 3 of them

#RequireAdmin
#Include <Array.au3>
#Include <File.au3>
ConsoleWrite(@ScriptDir&@CRLF)
$arr = _FileListToArray(@ScriptDir)
$tmp = False
For $x = 1 To $arr[0]
    If $arr[$x] ='config.ini' Then
        MsgBox(64,'_FileListToArray',$arr[$x])
        $tmp = True
        ExitLoop 1
    EndIf
Next
If $tmp = False Then MsgBox(48,'_FileListToArray','cant finde it in array')

$configFile = FileFindFirstFile(@ScriptDir&"config.ini")
If $configFile = -1 Or @error Then
    MsgBox(48, "FileFindFirstFile", "Error: unable to find config.ini file.")
Else
    MsgBox(64, "FileFindFirstFile", "Found config.ini file")
EndIf
FileClose($configFile)

If FileExists(@ScriptDir&"config.ini") Then
    MsgBox(64, "FileExists", "Found config.ini file")
Else
    MsgBox(48, "FileExists", "Error: Unable to find config.ini file.")
EndIf
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

No need to put the result to a variable, just use it this way.

If FileExists("config.ini") Then
MsgBox(0, "config.ini File", "Exists")
Else
MsgBox(0, "config.ini File", "Does NOT exists")
EndIf

Tested, working.

Just remember, it search for the file in script's directory.

Share this post


Link to post
Share on other sites

It doesn't work for me, what did I do wrong?

I posted the whole script :)


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

it means that your creating ini in wrong folder


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

I have the script located in the same folder where the config.ini file is (they're both in C:Users****DesktopTest Foldersamples).

When I run it, and the config.ini file is in the same folder, it doesn't show any message. However, if I move the file to the folder "Test Folder", it

prompts the message box saying that the file couldn't be found.


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

restart comp

after it try this on desktop folder

#RequireAdmin
#include <File.au3>
If Not _FileCreate("config.ini") Then MsgBox(4096,"Error", " Error Creating:" & @error)
If FileExists("config.ini") Then MsgBox(0, "config.ini File", "Exists")
FileDelete("config.ini")
If Not FileExists("config.ini") Then MsgBox(0, "config.ini File", "Does NOT exists")

it shud geave you 2 msgboxes, firstone after creating file with script second one after deliting it

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

bogQ, that worked


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

I feel so stupid now, I had 2 copies of the script, one updated, and one outdated.

One was saved on the desktop, and another in the folder. I kept running the outdated one :|

Thanks everyone :)


"The story of a blade is linked in Blood." 

―Yasuo

 

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

no need to feel that way it happend to everyone, just note, easiest way to run the script is by pressing F5 in scite editor, if you do it like that you'll know what script are you runing

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0