From: fishy on
I have several files that I import every day but I have to manually rename
them by removing the date/time stamp from the name i.e.

ICM_AMS_MS_Call_Stats_01011901000000.csv

has to become ICM_AMS_MS_Call_Stats.csv due to my import script.

These are saved to the same filepath every day so I need some function that
will rename the files to trim the datestamp before I call the import.

Any help would be appreciated
From: Douglas J. Steele on
Try:

Dim lngLastUnderscore As Long
Dim strNewName As String

lngLastUnderscore = InStrRev(strName, "_")
If lngLastUnderscore > 0 Then
strNewName = Left(strName, lngLastUnderscore - 1) & ".csv"
Else
strNewName = strName
End If

--
Doug Steele, Microsoft Access MVP
http://www.AccessMVP.com/DJSteele
(no e-mails, please!)

"fishy" <fishy(a)discussions.microsoft.com> wrote in message
news:AD46380F-E56B-475C-AE5E-C84EE37E92D5(a)microsoft.com...
>I have several files that I import every day but I have to manually rename
> them by removing the date/time stamp from the name i.e.
>
> ICM_AMS_MS_Call_Stats_01011901000000.csv
>
> has to become ICM_AMS_MS_Call_Stats.csv due to my import script.
>
> These are saved to the same filepath every day so I need some function
> that
> will rename the files to trim the datestamp before I call the import.
>
> Any help would be appreciated


From: Stuart McCall on
"fishy" <fishy(a)discussions.microsoft.com> wrote in message
news:AD46380F-E56B-475C-AE5E-C84EE37E92D5(a)microsoft.com...
>I have several files that I import every day but I have to manually rename
> them by removing the date/time stamp from the name i.e.
>
> ICM_AMS_MS_Call_Stats_01011901000000.csv
>
> has to become ICM_AMS_MS_Call_Stats.csv due to my import script.
>
> These are saved to the same filepath every day so I need some function
> that
> will rename the files to trim the datestamp before I call the import.
>
> Any help would be appreciated

Dim strOldName As String, strNewName As String
Dim strPath As String

strPath = "C:\Temp\" 'Change this to the correct path

strOldName = strPath & "ICM_AMS_MS_Call_Stats_01011901000000.csv"
strNewName = strPath & Left$(strOldName, InstrRev(strOldName, "_") - 1) &
".csv"

Name strOldName As strNewName

(then import from strNewName, of course)


From: fishy on

Apologies, the date/time stamp is of the format

ICM_AMS_MS_Call_Stats_YYYY-MM-DD_HH-MM-SS.csv

This therefore means that I am getting a bad filename error.

I thought I could get away with changing this to wildcards ie

ICM_AMS_MS_Call_Stats_****-**-**_**-**-**.csv

But this doesnt work.

Any ideas?

"Stuart McCall" wrote:

> "fishy" <fishy(a)discussions.microsoft.com> wrote in message
> news:AD46380F-E56B-475C-AE5E-C84EE37E92D5(a)microsoft.com...
> >I have several files that I import every day but I have to manually rename
> > them by removing the date/time stamp from the name i.e.
> >
> > ICM_AMS_MS_Call_Stats_01011901000000.csv
> >
> > has to become ICM_AMS_MS_Call_Stats.csv due to my import script.
> >
> > These are saved to the same filepath every day so I need some function
> > that
> > will rename the files to trim the datestamp before I call the import.
> >
> > Any help would be appreciated
>
> Dim strOldName As String, strNewName As String
> Dim strPath As String
>
> strPath = "C:\Temp\" 'Change this to the correct path
>
> strOldName = strPath & "ICM_AMS_MS_Call_Stats_01011901000000.csv"
> strNewName = strPath & Left$(strOldName, InstrRev(strOldName, "_") - 1) &
> ".csv"
>
> Name strOldName As strNewName
>
> (then import from strNewName, of course)
>
>
> .
>
From: Stuart McCall on

"fishy" <fishy(a)discussions.microsoft.com> wrote in message
news:CCE95E35-AFFD-472F-AB28-4F308A9F42F2(a)microsoft.com...
>
> Apologies, the date/time stamp is of the format
>
> ICM_AMS_MS_Call_Stats_YYYY-MM-DD_HH-MM-SS.csv
>
> This therefore means that I am getting a bad filename error.
>
> I thought I could get away with changing this to wildcards ie
>
> ICM_AMS_MS_Call_Stats_****-**-**_**-**-**.csv
>
> But this doesnt work.
>
> Any ideas?

Is the part "ICM_AMS_MS_Call_Stats" always the same? If not, does it ever
contain a number?