Jump to content
Sign in to follow this  

Put Todays Date Into The Filename

Recommended Posts

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)


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.")

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)


; Close the search handle

Share this post

Link to post
Share on other sites

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 & '"')

FileMove($searchdir & "\" & $FileList[1], $searchdir & "\" & StringReplace(_DateTimeFormat(_NowCalc(), 2), "/", "-") & ".csv")

Edit: Tidied code

Edited by smartee

Share this post

Link to post
Share on other sites

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....

Share this post

Link to post
Share on other sites

If I wanted to attach the newly named file, how would I call it?

I Tried 

$AttachFiles = (_DateTimeFormat(_NowCalc(), 2), "/", "-") & ".pdf"

Share this post

Link to post
Share on other sites

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

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...