Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2004
    Posts
    99

    Unanswered: make a script to change filename to include current YYYYMMDD

    Let me start off by saying that I am not a VB programmer.. but this forum has helped me out before so I'm hoping that I can get some help again !!!

    I need to rename a file on a daily basis so that the filename contains the current date in YYMMDD format.

    my original filename is FILENAMEsc_S.csv and I need to rename it to
    NEWFILENAME.YYYYMMDD.csv

    Can this be done programmatically with some basic VB code????

    I need to create this in a script so that I can run it once a day via windows scheduler

    any help would be greatly appreciated!

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by jpotucek
    NEWFILENAME.YYYYMMDD.csv
    That's not a valid filename - you cannot use dots...

    Is the file always in the same place?
    Is it in a folder on it's own?

    Why do you even need to rename it?
    Do you want to make a copy with a new name or simply change the filename?
    George
    Home | Blog

  3. #3
    Join Date
    Mar 2004
    Posts
    99
    I have an application that exports data to a .csv file everyday to the same folder on a Server. the file name is static.. always FILENAME_S.csv

    now I have a requirement to send this file daily to the Vendor that hosts our companies website. They are requiring me to send the file in the following format: Companyname_YYYYMMDD.csv (I substituted the '.' in the filename with '_')

  4. #4
    Join Date
    Mar 2004
    Posts
    99
    This is erroring out on line 1 character 12 'expected end of statement' not sure what is wrong ????

    Dim myFile as String
    Dim myNewFile as String
    myfile = "C:\filename_s.csv"
    myNewFile = "C\newfilename" & Format(Date, "yyyymmdd") & ".csv"
    Name myfile As myNewFile

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    If this is a vbs, don't try to declare the datatype.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Jun 2004
    Location
    Arizona, USA
    Posts
    1,848
    Quote Originally Posted by jpotucek
    This is erroring out on line 1 character 12 'expected end of statement' not sure what is wrong ????

    Dim myFile as String
    Dim myNewFile as String
    myfile = "C:\filename_s.csv"
    myNewFile = "C\newfilename" & Format(Date, "yyyymmdd") & ".csv"
    Name myfile As myNewFile
    You seem to be using ASP, and not VB.

    ASP doesn't support the use of declaring a variable as typed variables. They are ALL variants.

    The correct format is Dim myFile.

    Also, I don't believe that ASP supports the Name sub. I believe you'll need to use fso to rename the file.

    I'm moving this thread to the correct forum.
    Lou
    使大吃一惊
    "Lisa, in this house, we obey the laws of thermodynamics!" - Homer Simpson
    "I have my standards. They may be low, but I have them!" - Bette Middler
    "It's a book about a Spanish guy named Manual. You should read it." - Dilbert


  7. #7
    Join Date
    Apr 2007
    Posts
    29
    You should have to use the FSO object but unfortunately the FileSystemObject doesn't contain a Rename method; it does, however, have a method that can be used as a substitute for Rename: MoveFile.

    Check out the following code. You have to change the oldName variable value every time you want to rename the file.

    Code:
    <%
    DIM dDay, mMonth, yYear, fdate, newName, oldName, fFormat, objFSO
        oldName="20071205.csv"
        fFormat=".csv"
          dDay = Day(Date)
             mMonth = Month(Date)
          yYear   = Year(Date)
        newName = yYear & Right(Cstr(mMonth + 100),2) & Right(Cstr(dDay + 100),2) & fFormat
    
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    objFSO.MoveFile Server.MapPath(oldName), Server.MapPath(newName)
    Set objFSO = Nothing
    %>
    HTH,

    Khurram.

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Can I ask why we're doing this in ASP anyway?
    George
    Home | Blog

  9. #9
    Join Date
    Apr 2007
    Posts
    29
    Quote Originally Posted by georgev
    Can I ask why we're doing this in ASP anyway?
    Because he posted in an ASP forum. Plus he is a VB Developer and I have used VBScript inside ASP which he can understand without a single problem. Also IIS is free available with Windows Server OS so ASP page can be integrated with windows scheduler without any issue.

    HTH,

    Khurram.

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    That's not what I meant
    It simply feels like a bizzare platform to acheive our goal. But I guess if that's what (s)he is familiar with then there's no harm done. It just occured to me that it'd be far easier doing it another way. Also, if this is in ASP it can't be a scheduled jo, it'd run every time you visit the page?
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •