VladProgramatorul

AutoIt doesn't create file in ScriptDir

10 posts in this topic

#1 ·  Posted

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 ! :)

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

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.

Share this post


Link to post
Share on other sites

#4 ·  Posted

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

2 people like this

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thank you so much !

I didn't think not even a second this could be the problem :)

Share this post


Link to post
Share on other sites

#6 ·  Posted

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?

Share this post


Link to post
Share on other sites

#7 ·  Posted

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

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#8 ·  Posted

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! :)

 

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#10 ·  Posted

I am learning how to optimize my code.  You are not only delivering knowledge but good karma on the forum which is sometimes more needed then anything else in life. Thank You very much for all of that.

1 person likes this

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