bb01 Posted April 6, 2011 Share Posted April 6, 2011 I'm trying to build a new script to make things easier here.. it does everything that i want it too... Except now i need it to find the csv file & then rename it to today's date.csv & that's where I'm having problems... I know its probably due to my brain being fried from all this scripting.. but any help would be useful... #include <GUIConstantsEx.au3> #include <DateTimeConstants.au3> Opt('MustDeclareVars', 1) Date_() Func Date_() Local $n, $msg,$hSearch, $sFoundFile, $sFilePath, $replacer $hSearch = FileFindFirstFile(@ScriptDir & "\*.csv") ; Check if the search handle is valid If $hSearch = -1 Then MsgBox(0, "Wheres The CSV Sheet?", "No csv files found" & _ @CRLF & @CRLF & " Make sure its in the same folder as this File.") Exit EndIf While 1 ; Find the next file ; i.e. returns a string containing the value of 01-08-2010.csv $sFoundFile = FileFindNextFile($hSearch) If @error Then ExitLoop ; Create a full path using @ScriptDir and the found file $sFilePath = @ScriptDir & '\' & $sFoundFile ; The found file and the filepath are now available for use ; ; The next line shows what the found file is without the csv $replacer = StringReplace ( $sFoundFile, "EOMTemplate", $DTS_SHORTDATEFORMAT) ExitLoop WEnd ; Close the search handle FileClose($hSearch) Link to comment Share on other sites More sharing options...
smartee Posted April 6, 2011 Share Posted April 6, 2011 (edited) You might be over-complicating things a bit, try this#include <File.au3> #include <Array.au3> #include <Date.au3> $searchdir = @ScriptDir $FileList = _FileListToArray($searchdir, "*.csv") If @error = 4 Then MsgBox(0, "Where is The CSV Sheet?", "No csv files found" & _ @CRLF & 'Make sure its in "' & $searchdir & '"') Exit EndIf FileMove($searchdir & "\" & $FileList[1], $searchdir & "\" & StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-") & ".csv") Edit: Tidied code Edited April 6, 2011 by smartee Link to comment Share on other sites More sharing options...
bb01 Posted April 7, 2011 Author Share Posted April 7, 2011 that works perfect.. thanks for that... Yes i know i was going the long windded way... & after working on these scripts (got over 60 of them) for god only knows how long.. its fried my brain.... Link to comment Share on other sites More sharing options...
fuzzie Posted December 2, 2014 Share Posted December 2, 2014 If I wanted to attach the newly named file, how would I call it? I Tried $AttachFiles = (_DateTimeFormat(_NowCalc(), 2), "/", "-") & ".pdf" Link to comment Share on other sites More sharing options...
Xenobiologist Posted December 2, 2014 Share Posted December 2, 2014 What do you mean by attach? Rename it in another way? Send it via email? Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
fuzzie Posted December 2, 2014 Share Posted December 2, 2014 Renaming it work, thanks! 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