Jump to content

AutoIt doesn't create file in ScriptDir


Recommended Posts

Hello !

Yesterday, I tested my script and that created a file well in my script directory but today i don't know what happened and this don't create at all.

The problem is that even if i create a new script file this don't create any file.

 

I've tried to run as administrator but it don't work and no error display.

I want to tell you that the script can create the file anywhere in my computer but only in script directory not.

 

The script is actually, a little big (1739 lines) so I can't paste here but I think is not the problem from the script since this don't let me from any other scripts to create.

 

Any solutions ?

Thank you ! :)

 

Link to comment
Share on other sites

  • Developers

Show how you write to the file. Do you have the fully qualified path in it or just the filename? In case of the latter: what is the WorkDir when writing to the file?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi !

Thank you for your fast response !

 

The code look like that :

 

FileOpen("File.txt", 1)

FileWriteLine("File.txt", "Write something")
FileClose("File.txt")

______________________________________

I also tried :

FileOpen(@ScriptDir & "File.txt", 1)

FileWriteLine(@ScriptDir & "File.txt", "Write something")
FileClose(@ScriptDir & "File.txt")

______________________________________

I tried to change the mode that open the file but with no results.. :(

The WorkDir is the same as ScriptDir.

Link to comment
Share on other sites

  • Developers
Just now, VladProgramatorul said:

FileOpen(@ScriptDir & "File.txt", 1)

FileWriteLine(@ScriptDir & "File.txt", "Write something")
FileClose(@ScriptDir & "File.txt")

This is invalid coding as you need to use the FileHandle returned by FileOpen!
On top of that you are missing a backslash before the filename. Something like this should be the correct way:

$fh = FileOpen(@ScriptDir & "\File.txt", 1)
FileWriteLine($fh, "Write something")
FileClose($fh)

The helpfile is your friend ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Don't get me wrong because i want to learn this code also, it doesn't matter if at the end of the code you get

FileClose(FileOpen(@ScriptDir & "\File.txt", 1))

File will be closed anyway because its the last executed command, right?

Link to comment
Share on other sites

  • Developers

Not sure why you show the FileOpen() inside the FileClose(), but yes, at the end of the script execution all handles will be closed and memory freed. 
It will be an issue though when you do those 3 commands repeatedly in a loop leaving all those files instances open.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thank You for your answer. You are very active and have a lot of patience to help novice people which is really nice to see apart from programming part.

So...   if you have
 

$fh = FileOpen(@ScriptDir & "\File.txt", 1)

then content of the

$fh

after that line is just path to file.txt:

@ScriptDir & "\File.txt"

not 

FileOpen(@ScriptDir & "\File.txt", 1)

right?

I have gaps like that because I didnt learn it the way it should be learned. just when I need something then I go and search, borrow and code. Thanks! :)

 

 

Link to comment
Share on other sites

  • Developers

You must also open a file before any I/O operation can be performed on it. FileOpen allocates a buffer for I/O to the file and determines the mode of access to use with the buffer. The FileHandle is a reference to this allocated buffer/file.
So in case in AutoIt3 you only have an FileRead() statement, then under the hood, AutoIt3 will do an FileOpen(), FileRead(), FIleCLose(). 
That is also why an FileOpen(), then looping through the records and ending with an FileCLose() is much faster then only using a FileRead(filename, Recordnumber) as that avoids maybe Open/Close actions.

JOs

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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