DShell Posted February 17, 2016 Share Posted February 17, 2016 Hello Forum, I have been working on a Autoit script to do the following: 1. When a "get csv" button is pressed a batch file will be called that produces this csv file in a certain folder 2. Then a "move csv" button is pressed that will move the csv file to a different folder if the folder structure is not there create it and overwrite 3. Script includes function that searches for csv file an puts it into an array then stores in in a variable that the function returns 4. Display message box of path and name of file 4. I was able to create the new directory structure and the message box displayed the path and filename successfully but the file itself was not moved. Here is a gist of what I am attempting to do: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $csvmoverForm = GUICreate("Form1", 209, 216, 296, 431) Global $getcsvButton = GUICtrlCreateButton("get csv", 24, 56, 145, 41) Global $movecsvButton = GUICtrlCreateButton("move csv", 25, 126, 145, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $datapath = "C:\data\" Global $newdatapath = "C:\newdata\" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $getcsvButton RunWait("C:\runtoproducecsv.bat") ; this bat file will produce a csv file in dirctory C:\data\csvfile_date_time.csv Exit Case $movecsvButton FileMove("_GetCsvFile($datapath)",$newdatapath & "\data1\",$FC_OVERWRITE + $FC_CREATEPATH) MsgBox(0, '', __GetCsvFile($datapath)) Exit EndSwitch WEnd Func _GetCsvFile($arg) Local $first = FileFindFirstFile($arg & "csvfile*.csv"), $array[1] ;code line ;code line Return $filename ;returns the path and filename EndFunc Thanks for any feedback Link to comment Share on other sites More sharing options...
InunoTaishou Posted February 17, 2016 Share Posted February 17, 2016 My guess is the file is in use by your FileFindFirstFile call. Do you call FileClose when you're finished searching and return $filename? More code is needed to get an accurate testing because just returning a path to a valid file works for me. Since we don't know how you're processing your _GetCsvFile function. Link to comment Share on other sites More sharing options...
Skysnake Posted February 17, 2016 Share Posted February 17, 2016 Case $movecsvButton FileMove("_GetCsvFile($datapath)",$newdatapath & "\data1\",$FC_OVERWRITE + $FC_CREATEPATH) ConsoleWrite('$newdatapath & "\data1\"' & $newdatapath & "\data1\" & @CRLF) ; <<<<<<<<<<<<<< is there a filename here? MsgBox(0, '', __GetCsvFile($datapath)) Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
water Posted February 17, 2016 Share Posted February 17, 2016 Shouldn't you remove the quotes to call function _GetCSVFile? FileMove(_GetCsvFile($datapath), $newdatapath & "\data1\", $FC_OVERWRITE + $FC_CREATEPATH) My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
DShell Posted February 17, 2016 Author Share Posted February 17, 2016 Hi Guys(&Girls), Thanks for the responses: @InunoTaishou Yes, I did include FileClose() see below for more code @Skysnake No there is not, but I did not see one in the Help File example: Quote FileMove(@TempDir & "\*.au3", @TempDir & "\Au3Files\", $FC_OVERWRITE + $FC_CREATEPATH) Further, that was the point of attempting to get the file into a variable so that when I moved it it would keep the same name. @water You are indeed correct it was a typo in the demo code, there should be no quotes. The function used to getcsv file was not created by me and credit goes to the original creator (I think it was found on this forum).I just found it it my research and am attempting to modify it to suit my purposes outlined above. So credit goes to him/her. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= Global $csvmoverForm = GUICreate("Form1", 209, 216, 296, 431) Global $getcsvButton = GUICtrlCreateButton("get csv", 24, 56, 145, 41) Global $movecsvButton = GUICtrlCreateButton("move csv", 25, 126, 145, 41) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $datapath = "C:\data\" Global $newdatapath = "C:\newdata\" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $getcsvButton RunWait("C:\runtoproducecsv.bat") ; this bat file will produce a csv file in dirctory C:\data\csvfile_date_time.csv Exit Case $movecsvButton FileMove(_GetEjournalReg1CsvFile($qdriverpath),$ejpathreg1 & "\reg1\*.csv",$FC_OVERWRITE + $FC_CREATEPATH) MsgBox(0, '', _GetEjournalReg1CsvFile($qdriverpath)) Exit EndSwitch WEnd Func _GetEjournalReg1CsvFile($arg) If StringRight($arg, 1) <> '\' Then $arg &= '\' Local $first = FileFindFirstFile($arg & "ejournalreg1*.csv"), $array[1], $hold, $ret, $split ;$filename While 1 $found = FileFindNextFile($first) If @error Then ExitLoop ; check if a found file is a directory. if it is, skip it, and ; continue to the next iteration in the loop. If StringInStr(FileGetAttrib($arg & $found), 'D') Then ContinueLoop ; put the file's date/time and path/name in the array. ; example entry: 20070514095200|c:\windows\somefile.ext $array[UBound($array) - 1] = FileGetTime($arg & $found, 1, 1) & '|' & $arg & $found ; increase the size of the array by 1 to make room for another entry. ReDim $array[UBound($array) + 1] WEnd FileClose($first) ; at this point, $array is holding all the time/dates and path/file in each element. ; $items represents an item in an array index, for each . For $items In $array ; split the array element's string at '|' making $split[1] hold the date and ; split[2] hold the path/file $split = StringSplit($items, '|') ; if $split[1], the date, is greater than $hold... If $split[1] > $hold Then ; ...then we want $hold to become the value of the date... $hold = $split[1] ; ...and if the date is a higher date, we want to save the path/file in $ret. $ret = $split[2] ; save the path/file in $ret. $ret = $split[2] EndIf Next ; when all is finished, $ret holds the path/file so we Return it. Return $ret EndFunc ; End _GetEjournalReg1CsvFile If I got this working then I would modify it to not pay attention to the time created, just store move file into array and then move to new location with same filename. Link to comment Share on other sites More sharing options...
DShell Posted February 17, 2016 Author Share Posted February 17, 2016 Addendum - in my second script snippet Please change Global $datapath = "C:\data\" ---> Global $qdriverpath = " C:\data\ " and Global $newdatapath = "C:\newdata\" ---> Global $ejpathreg1= " C:\newdata\ " Link to comment Share on other sites More sharing options...
DShell Posted March 24, 2016 Author Share Posted March 24, 2016 Please consider this post closed... I have found other solutions Thanks for all those who took the time to respond and to the original owner of the code. 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