Karl1983 Posted August 18, 2013 Share Posted August 18, 2013 Hello. Noob alert! I am willing to learn and write my own code so apologies if I am plain stupid. I will try not to be one of those who supplies little information as I see replies to suggest that it really annoys you. So Maybe some background before I issue the problem statement. I have a simple GUI that allows you to enter a location and destination for a folder copy and to elect to override files or not (why write such a programme when software already out there? Well because I want to, its fun to learn) So anyway, what I do is I create a file at the start to pre-populate the fields with a destination and source (if it doesnt already exist) Func _FilePathCall() $file = FileOpen(@ScriptDir & "\filepath.csv", 0) If $file = -1 Then FileWrite(@scriptdir & "\filepath.csv", "C:\" & @CRLF ) FileWrite(@scriptdir & "\filepath.csv", "C:\") FileClose($file) MsgBox(0,"Notification","Done") EndIf EndFunc This works fine (and hopefully isn't causing my issue later on) Later I call this file to set the input boxes Func _SetSrcFromFile() $file = FileOpen(@ScriptDir & "\filepath.csv", 0) $src1 = FileReadLine($file,1) FileClose($file) GUICtrlSetData($srcinput,$src1) EndFunc But I also have a button to allow people to select a new source and so as part of that process I want it to write back to the file so that this becomes the new default source location (like a memory if you like). Now I am struggling with this function. I cant seem to get it to work. I will post to variations I have tried, but neither seem to update the file in question. Version 1; Func _SetNewSrc() $src2 = FileSelectFolder("Please Select Backup SOURCE","") ;user prompt to select a folder _FileWriteToLine($file, 1, $src2, 1) EndFunc So as you can hopefully see in this version I simply just use the function to write to line of file without using fileopen...this could be wrong but I tried this incase the fileopen was not needed. I am attempting to replace the text already saved in line 1 Version 2 - Exactly the same except using FileOpen Func _SetNewSrc() $file = FileOpen(@ScriptDir & "\filepath.csv", 1) $src2 = FileSelectFolder("Please Select Backup SOURCE","") ;user prompt to select a folder _FileWriteToLine($file, 1, $src2, 1) FileClose($file) EndFunc I set it to allow write access in the FileOpen and even tried deleting the data in that process but the _FileWriteToLine still does not work. And actually...deleting the data is not what I want anyway as line 2 contains destination data which I would want to keep and update as part of another similar function. Can anyone help? I can post full code if you like but it is Nooblike and rather scary and probably uses 10x the amount of code needed Look forward to some help. And of course I have looked up this elsewhere...thats where I found to use the _FileWriteToLine in the first place but it wasnt on a post that was related closely enough Regards Karl Griffiths Link to comment Share on other sites More sharing options...
JohnOne Posted August 18, 2013 Share Posted August 18, 2013 First thing you do is check @error after call to _FileWriteToLine AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Solution ajag Posted August 18, 2013 Solution Share Posted August 18, 2013 (edited) Hi Kalrl1983, try Func _SetNewSrc() $src2 = FileSelectFolder("Please Select Backup SOURCE","") ;user prompt to select a folder _FileWriteToLine(@ScriptDir & "\filepath.csv", 1, $src2, 1) EndFunc It seems that _FileWriteToLine() does not accept a filehandle, so give the path-string to it. A-Jay Edited August 18, 2013 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 More sharing options...
Karl1983 Posted August 18, 2013 Author Share Posted August 18, 2013 Hi A-Jay Spot on. Thank you for responding so quickly! I have run this and it now updates correctly. Many thanks JohnOne - noted re using error handling to assist in debugging Thanks again Regards Karl Griffiths Link to comment Share on other sites More sharing options...
AZJIO Posted August 18, 2013 Share Posted August 18, 2013 Func _SetNewSrc() $tmp = FileSelectFolder("Please Select Backup SOURCE", "") ;user prompt to select a folder If @error Then Return SetError(1, 0, 'Error') _FileWriteToLine(@ScriptDir & "\filepath.csv", 1, $tmp, 1) EndFunc ;==>_SetNewSrc My other projects or all Link to comment Share on other sites More sharing options...
Karl1983 Posted August 18, 2013 Author Share Posted August 18, 2013 (edited) Thanks Universalist. I have taken on board the suggestions and also amended the code so the function can be called for each input and relevant line in csv to call Thanks again all for your help. ;Setting a new default input(done everytime the Dir location is amended) Func _SetNewDir($inputname, $csvLine) $tmp = FileSelectFolder("Please Select Backup Source","") ;user prompt to select a folder If @error Then Return SetError(1, 0, 'Error') _FileWriteToLine(@ScriptDir & "\filepath.csv", $csvLine, $tmp, 1) ;Writes the new location to the filepath csv used in 'Func _FilePathCall()' $file = FileOpen(@ScriptDir & "\filepath.csv", 0) ;Opens file with read access $DirSelect = FileReadLine($file,$csvLine) ;Reads the new location that has been set FileClose($file) GUICtrlSetData($inputname,$DirSelect) ;Sets the input box to reflect the new location EndFunc ;==>_SetNewDir Edited August 18, 2013 by Karl1983 Regards Karl Griffiths Link to comment Share on other sites More sharing options...
Karl1983 Posted August 19, 2013 Author Share Posted August 19, 2013 Link back to full script. A work in progress:- Regards Karl Griffiths Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now