kra55 Posted February 12, 2011 Share Posted February 12, 2011 hey all sorry to ask a stupid question. Ive been staring at this one little bit of basic code for an hour and its doing my head in. basically it works in one script but not another and i cannot figure out why. I have put indicators in my code to ensure it is reaching it and it does nothing but continue on. When tested in a fresh script it works fine(as in creates the file when it does not exist and allow writing). If somone could tell me why its not working that would be great..... $file1 = FileOpen("bset.txt", 1) If $file1 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileClose($file1) Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 12, 2011 Moderators Share Posted February 12, 2011 kra55,it does nothing but continue onWhy should it not carry on? If the file exists you open it for appending text, and if it does not you create it. What were you expecting to happen? 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...
kra55 Posted February 12, 2011 Author Share Posted February 12, 2011 (edited) in the scipt i want it to work in. The scipt continues on and does not create the file. When i create a fresh empty script with this code. It script creates the file as it should. sorry im never as clear/to the point as i should be (tested by deleting file when it does actually exist) Edited February 12, 2011 by kra55 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 12, 2011 Moderators Share Posted February 12, 2011 kra55, Could you post all of the code where you get this problem? There is no reason why the code you posted above should fail to create a file, so there must be something else preventing it. 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...
kra55 Posted February 14, 2011 Author Share Posted February 14, 2011 The code mentioned is in the addfiletolist() function. Ive just figured out that its placing the file where in what ever folder i selected a file using the fileopendialog. I figure the solution would be for me to simply specify the folder during the fileopen process. This should resolve any issues. Now just need to find a function to return the current script location and i should start moving forward again. Even tho i think i know how to make it work it would be great if someone could actually tell me whats happening. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=C:\Documents and Settings\kris\My Documents\Scripts\gui\Forms\backupform.kxf $Form1 = GUICreate("Backup Util", 627, 412, 192, 124) $afileBut = GUICtrlCreateButton("Add File", 56, 304, 89, 25) GUICtrlSetOnEvent($afileBut, "addfiletolist") $afoldBut = GUICtrlCreateButton("Add Folder", 160, 304, 83, 25) GUICtrlSetOnEvent($afoldBut, "addfoldtolist") $remBut = GUICtrlCreateButton("Remove", 256, 304, 75, 25) $Label1 = GUICtrlCreateLabel("Insert 'To' Folder:", 360, 264, 91, 17) $desInput = GUICtrlCreateInput("c:\backup\", 456, 264, 121, 21) $browBut = GUICtrlCreateButton("Browse", 408, 296, 121, 25) $Label2 = GUICtrlCreateLabel("Overwrite with no prompt?:", 16, 344, 130, 17) $overCom = GUICtrlCreateCombo("yes", 160, 344, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "no") $Label3 = GUICtrlCreateLabel("", 32, 384, 4, 4) $Label4 = GUICtrlCreateLabel("Backup Backup File?", 32, 376, 106, 17) $bbCom = GUICtrlCreateCombo("no", 160, 368, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "yes") $startBut = GUICtrlCreateButton("Start Backup", 464, 352, 139, 41) GUICtrlSetOnEvent($startBut, "copyfiles") $savBut = GUICtrlCreateButton("Save Settings", 296, 352, 147, 41) GUICtrlSetOnEvent($savBut, "ssettings") $File = GUICtrlCreateTab(8, 24, 609, 225) $TabSheet1 = GUICtrlCreateTabItem("Files") $fileList = GUICtrlCreateListView("File Name|Location", 12, 49, 593, 193) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 600) $TabSheet2 = GUICtrlCreateTabItem("Folders") GUICtrlSetState(-1,$GUI_SHOW) $foldList = GUICtrlCreateListView("Folder Name|Location", 12, 49, 593, 193) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 600) GUICtrlCreateTabItem("") GUICtrlSetState($TabSheet1,$GUI_SHOW) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd func dupcheck($col1, $col2, $listview) $count = 0 $founddup = 0 while $count < _GUICtrlListView_GetItemCount($listview) if _GUICtrlListView_GetItemText($listview, $count, 0) == $col1 And _GUICtrlListView_GetItemText($listview, $count, 1) == $col2 Then $count = _GUICtrlListView_GetItemCount($listview) $founddup = 1 EndIf $Count = $Count + 1 WEnd Return $founddup EndFunc func addfiletolist() $filenam = "" $fileloc = "" $message = "Hold down Ctrl or Shift to choose multiple files." $filefpath = FileOpenDialog($message, "", "All (*.*)", 1 + 4 ) If StringInStr($filefpath, "|") <> 0 Then $paths = StringSplit($filefpath,"|") $file1 = FileOpen("bset.txt", 1) If $file1 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $i = 2 to $paths[0] $filenam = $paths[$i] $fileloc = $paths[1] If dupcheck($filenam, $fileloc, $filelist) == 1 Then MsgBox(0,"Already in list", "selection already in list") Else FileWrite($file1, $fileloc & $filenam & ",1,0,") If _GUICtrlListView_GetItemCount($filelist) == 0 Then _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, 0, $fileloc, 1) else _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, _GUICtrlListView_GetItemCount($filelist)-1, $fileloc, 1) EndIf EndIf next FileFlush($file1) FileClose($file1) Else $filenam = StringRight($filefpath, stringlen($filefpath )- StringInStr($filefpath, "\", 0, -1)) $fileloc = StringLeft($filefpath, StringInStr($filefpath, "\", 0, -1)) If dupcheck($filenam, $fileloc, $filelist) == 1 Then MsgBox(0,"Already in list", "selection already in list") Else $savs = FileOpen("bset.txt", 1) If $savs = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ;FileWrite($file1, ($fileloc & $filenam & ",1,0,")) FileClose($savs) If _GUICtrlListView_GetItemCount($filelist) == 0 Then _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, 0, $fileloc, 1) else _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, _GUICtrlListView_GetItemCount($filelist)-1, $fileloc, 1) EndIf EndIf EndIf endfunc func addfoldtolist() $foldnam = "" $fileloc = "" $message = "Select folder and click ok." $foldfpath = FileSelectFolder($message, "") $foldnam = StringRight($foldfpath, stringlen($foldfpath )- StringInStr($foldfpath, "\", 0, -1)) $foldloc = $foldfpath If dupcheck($foldnam, $foldloc, $foldlist) == 1 Then MsgBox(0,"Already in list", "selection already in list") Else If _GUICtrlListView_GetItemCount($foldlist) == 0 Then _GUICtrlListView_AddItem($foldlist, $foldnam) _GUICtrlListView_AddSubItem($foldlist, 0, $foldloc, 1) else _GUICtrlListView_AddItem($foldlist, $foldnam) _GUICtrlListView_AddSubItem($foldlist, _GUICtrlListView_GetItemCount($foldlist)-1, $foldloc, 1) EndIf EndIf endfunc Func ssettings() EndFunc Func lsettings() EndFunc func copyfiles() $count = 0 while $count < _GUICtrlListView_GetItemCount($filelist) $dir = _GUICtrlListView_GetItemText($filelist, $count, 1) & _GUICtrlListView_GetItemText($filelist, $count, 0) $dest = GUICtrlRead($desInput) $newdest = $dest & stringright(_GUICtrlListView_GetItemText($filelist, $count, 1), stringlen(_GUICtrlListView_GetItemText($filelist, $count, 1)) -3) MsgBox(0,"test",$newdest) if FileExists($newdest & _GUICtrlListView_GetItemText($filelist, $count, 0)) == 0 Then FileCopy($dir, $newdest,8) Sleep(100) Else EndIf $count = $count + 1 WEnd endfunc Func OnExit() Exit EndFunc ;==>OnExit Link to comment Share on other sites More sharing options...
BrewManNH Posted February 14, 2011 Share Posted February 14, 2011 If you're looking to find out how to tell where the script is being executed from, you can use the @ScriptDir macro. A couple of things I noticed right away though. Inside your While...Wend loop you're using GUIGetMsg, but you are using OnEvent mode. That part of your code won't do anything, GUIGetMsg will always return 0 if you're using OnEvent mode. The second thing I noticed is that your script is causing CPU utilization to be pegged at 100%. You need to put a Sleep() inside your While loop, if you use Sleep(20) it will lower the CPU use down to about 10% at max while the script is idling. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
kra55 Posted February 14, 2011 Author Share Posted February 14, 2011 Took your advise - its now working when a single file is added. But when multiple files are added the file is not created and obviously no information is added. Please please assist driving me crazy even tho i feel i am moving forward again . expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=C:\Documents and Settings\kris\My Documents\Scripts\gui\Forms\backupform.kxf $Form1 = GUICreate("Backup Util", 627, 412, 192, 124) $afileBut = GUICtrlCreateButton("Add File", 56, 304, 89, 25) GUICtrlSetOnEvent($afileBut, "addfiletolist") $afoldBut = GUICtrlCreateButton("Add Folder", 160, 304, 83, 25) GUICtrlSetOnEvent($afoldBut, "addfoldtolist") $remBut = GUICtrlCreateButton("Remove", 256, 304, 75, 25) $Label1 = GUICtrlCreateLabel("Insert 'To' Folder:", 360, 264, 91, 17) $desInput = GUICtrlCreateInput("c:\backup\", 456, 264, 121, 21) $browBut = GUICtrlCreateButton("Browse", 408, 296, 121, 25) $Label2 = GUICtrlCreateLabel("Overwrite with no prompt?:", 16, 344, 130, 17) $overCom = GUICtrlCreateCombo("yes", 160, 344, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "no") $Label3 = GUICtrlCreateLabel("", 32, 384, 4, 4) $Label4 = GUICtrlCreateLabel("Backup Backup File?", 32, 376, 106, 17) $bbCom = GUICtrlCreateCombo("no", 160, 368, 105, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "yes") $startBut = GUICtrlCreateButton("Start Backup", 464, 352, 139, 41) GUICtrlSetOnEvent($startBut, "copyfiles") $savBut = GUICtrlCreateButton("Save Settings", 296, 352, 147, 41) GUICtrlSetOnEvent($savBut, "ssettings") $File = GUICtrlCreateTab(8, 24, 609, 225) $TabSheet1 = GUICtrlCreateTabItem("Files") $fileList = GUICtrlCreateListView("File Name|Location", 12, 49, 593, 193) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 600) $TabSheet2 = GUICtrlCreateTabItem("Folders") GUICtrlSetState(-1,$GUI_SHOW) $foldList = GUICtrlCreateListView("Folder Name|Location", 12, 49, 593, 193) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 600) GUICtrlCreateTabItem("") GUICtrlSetState($TabSheet1,$GUI_SHOW) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit") #EndRegion ### END Koda GUI section ### While 1 Sleep(20) WEnd func dupcheck($col1, $col2, $listview) $count = 0 $founddup = 0 while $count < _GUICtrlListView_GetItemCount($listview) if _GUICtrlListView_GetItemText($listview, $count, 0) == $col1 And _GUICtrlListView_GetItemText($listview, $count, 1) == $col2 Then $count = _GUICtrlListView_GetItemCount($listview) $founddup = 1 EndIf $Count = $Count + 1 WEnd Return $founddup EndFunc func addfiletolist() $filenam = "" $fileloc = "" $message = "Hold down Ctrl or Shift to choose multiple files." $filefpath = FileOpenDialog($message, "", "All (*.*)", 1 + 4 ) If StringInStr($filefpath, "|") <> 0 Then $paths = StringSplit($filefpath,"|") MsgBox(0,"test",@ScriptDir & "\bset.txt") $savs = FileOpen(@ScriptDir & "bset.txt", 1) If $savs = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf For $i = 2 to $paths[0] $filenam = $paths[$i] $fileloc = $paths[1] If dupcheck($filenam, $fileloc, $filelist) == 1 Then MsgBox(0,"Already in list", "selection already in list") Else FileWrite($savs, ($fileloc & $filenam & ",1,0,")) If _GUICtrlListView_GetItemCount($filelist) == 0 Then _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, 0, $fileloc, 1) else _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, _GUICtrlListView_GetItemCount($filelist)-1, $fileloc, 1) EndIf EndIf next FileFlush($savs) FileClose($savs) Else $filenam = StringRight($filefpath, stringlen($filefpath )- StringInStr($filefpath, "\", 0, -1)) $fileloc = StringLeft($filefpath, StringInStr($filefpath, "\", 0, -1)) If dupcheck($filenam, $fileloc, $filelist) == 1 Then MsgBox(0,"Already in list", "selection already in list") Else MsgBox(0,"test",@ScriptDir & "\bset.txt") $savs = FileOpen(@ScriptDir &"\bset.txt", 1) If $savs = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf FileWrite($savs, ($fileloc & $filenam & ",1,0,")) FileFlush($savs) FileClose($savs) If _GUICtrlListView_GetItemCount($filelist) == 0 Then _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, 0, $fileloc, 1) else _GUICtrlListView_AddItem($filelist, $filenam) _GUICtrlListView_AddSubItem($filelist, _GUICtrlListView_GetItemCount($filelist)-1, $fileloc, 1) EndIf EndIf EndIf endfunc func addfoldtolist() $foldnam = "" $fileloc = "" $message = "Select folder and click ok." $foldfpath = FileSelectFolder($message, "") $foldnam = StringRight($foldfpath, stringlen($foldfpath )- StringInStr($foldfpath, "\", 0, -1)) $foldloc = $foldfpath If dupcheck($foldnam, $foldloc, $foldlist) == 1 Then MsgBox(0,"Already in list", "selection already in list") Else If _GUICtrlListView_GetItemCount($foldlist) == 0 Then _GUICtrlListView_AddItem($foldlist, $foldnam) _GUICtrlListView_AddSubItem($foldlist, 0, $foldloc, 1) else _GUICtrlListView_AddItem($foldlist, $foldnam) _GUICtrlListView_AddSubItem($foldlist, _GUICtrlListView_GetItemCount($foldlist)-1, $foldloc, 1) EndIf EndIf endfunc Func ssettings() EndFunc Func lsettings() EndFunc func copyfiles() $count = 0 while $count < _GUICtrlListView_GetItemCount($filelist) $dir = _GUICtrlListView_GetItemText($filelist, $count, 1) & _GUICtrlListView_GetItemText($filelist, $count, 0) $dest = GUICtrlRead($desInput) $newdest = $dest & stringright(_GUICtrlListView_GetItemText($filelist, $count, 1), stringlen(_GUICtrlListView_GetItemText($filelist, $count, 1)) -3) MsgBox(0,"test",$newdest) if FileExists($newdest & _GUICtrlListView_GetItemText($filelist, $count, 0)) == 0 Then FileCopy($dir, $newdest,8) Sleep(100) Else EndIf $count = $count + 1 WEnd endfunc Func OnExit() Exit EndFunc ;==>OnExit Link to comment Share on other sites More sharing options...
BrewManNH Posted February 14, 2011 Share Posted February 14, 2011 Try this in place of your copyfiles function: Func copyfiles() $count = 0 While $count < _GUICtrlListView_GetItemCount($fileList) $dir = _GUICtrlListView_GetItemText($fileList, $count, 1) & "\" & _GUICtrlListView_GetItemText($fileList, $count, 0) $dest = GUICtrlRead($desInput) $newdest = $dest & _GUICtrlListView_GetItemText($fileList, $count, 0) MsgBox(0, "test", $newdest) If FileExists($newdest & _GUICtrlListView_GetItemText($fileList, $count, 0)) == 0 Then FileCopy($dir, $newdest, 8) Sleep(100) Else EndIf $count = $count + 1 WEnd EndFunc ;==>copyfiles If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator 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