yhu420 Posted November 26, 2014 Share Posted November 26, 2014 Hello everyone, I'd like my autoit program to create a new text file, and write things in it. As soon as I compile it, it works with no error, if I launch it in the build folder, the text file is created. However, if I move it elsewhere, it just wont create it, AND claim the file already exists ?! I do not thing it has anything to do with admin rights, as long as I tried it in many "common places", or ran it in admin mode, with the same results :/ Here is a snip: Dim $path $path = @ScriptDir & "\LOG.DAT" ;Dim $VarTmp ;$VarTmp = "" Dim $dll $dll = DllOpen("user32.dll") Dim $file $file = FileOpen($path, 1) ; 1-> write mode (append) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf I never got the error message, even though the file (LOG.DAT) is not created :/ What canI have done wrong? Thanks Link to comment Share on other sites More sharing options...
MikahS Posted November 26, 2014 Share Posted November 26, 2014 Welcome to the AutoIt forum! First off, when you moved it, did you check that directory for the created file? As @ScriptDir will change to the directory it was moved to. you can always check if you created the file successfully with a check with FileRead: $file = FileOpen($path, 1) Local $fRead = FileRead($file) If @error Then MsgBox(0, "", "Did not work") EndIf Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Jfish Posted November 26, 2014 Share Posted November 26, 2014 It works for me to run it in a folder, move it, then run it again. I see the files in both locations. I think if the exe is running perhaps you need to make sure you close the file? Can you post all of your code? Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
yhu420 Posted November 26, 2014 Author Share Posted November 26, 2014 (edited) Well, first Mikahs, I double checked by running a copy of the executable in another location and checking the text file of the first location, but still, nothing had changed :/ I've done a lot of tests before posting this, and I had the same issue with some other programs, therefore I gave up developing them, but now I'd really like to know whats wrong with that. To make sure the path is right, I implemented two additional lines: MsgBox(0,"debug", "Log: " & $path) Exit And, the path is correct for the two different locations, but only works for 1 :/ Then,Jfish, I'm trying to make a keyboard heatmap for statistics when playing tf2, to be precise here is moar code: expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=heat2.exe #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Misc.au3> Dim $Fichier $Fichier = @ScriptDir & "\LOG.DAT" ;Dim $VarTmp ;$VarTmp = "" Dim $dll $dll = DllOpen("user32.dll") Dim $file $file = FileOpen($Fichier, 1) ; Check if file opened for writing OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 ;Sleep ( 50 ) ;Kpres("01", "Left mouse button") ;Kpres("02", "Right mouse button") ;Kpres("04", "Middle mouse button") ;Kpres("05", "Windows 2000/XP: X1 mouse button") ;Kpres("06", "Windows 2000/XP: X2 mouse button") Kpres("08", "|BACKSPACE|") While _IsPressed("08") = 1 WEnd Kpres("09", "|TAB|") ; A lotta loops ; later on... WEnd DllClose($dll) func Kpres($num,$res) If _IsPressed($num, $dll) Then FileWrite($file, $res) Endif EndFunc FileClose($file) Do you need compiler options or something? Thanks for the support EDIT: more coherence with latly posted code Edited November 26, 2014 by yhu420 Link to comment Share on other sites More sharing options...
MikahS Posted November 26, 2014 Share Posted November 26, 2014 (edited) Just an FYI @ScriptDir is the directory the script is in, so if you move it, it changes. But, I'm not sure if this is considered gaming and is against the rules. Edited November 26, 2014 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Jfish Posted November 26, 2014 Share Posted November 26, 2014 Yes, please read the forum rules at bottom right of the screen. Game automation of any kind is not permitted. A mod will likely be along shortly to lock this thread. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 26, 2014 Moderators Share Posted November 26, 2014 yhu420, I'm trying to make a keyboard heatmap for statistics when playing tf2That sounds to me as if it breaks both the "game" and "keylogger" rules - thread locked. Plase read the Forum rules (there is also a link at bottom right of each page) befor eposting again. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts