Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > make a script to change filename to include current YYYYMMDD

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-04-07, 10:17
jpotucek jpotucek is offline
Registered User
 
Join Date: Mar 2004
Posts: 99
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!
Reply With Quote
  #2 (permalink)  
Old 05-04-07, 10:48
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,139
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
You only stop learning when you stop asking questions.
Reply With Quote
  #3 (permalink)  
Old 05-04-07, 12:21
jpotucek jpotucek is offline
Registered User
 
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 '_')
Reply With Quote
  #4 (permalink)  
Old 05-04-07, 16:21
jpotucek jpotucek is offline
Registered User
 
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
Reply With Quote
  #5 (permalink)  
Old 05-04-07, 16:29
Teddy Teddy is offline
Access Monkey.
 
Join Date: Mar 2003
Location: The Bottom of The Barrel
Posts: 4,930
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? ***
Reply With Quote
  #6 (permalink)  
Old 05-04-07, 16:31
loquin loquin is offline
Super Moderator
 
Join Date: Jun 2004
Location: Arizona, USA
Posts: 1,359
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

Reply With Quote
  #7 (permalink)  
Old 05-05-07, 04:21
khurram007 khurram007 is offline
Registered User
 
Join Date: Apr 2007
Posts: 28
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.
Reply With Quote
  #8 (permalink)  
Old 05-08-07, 04:41
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,139
Can I ask why we're doing this in ASP anyway?
__________________
George
You only stop learning when you stop asking questions.
Reply With Quote
  #9 (permalink)  
Old 05-08-07, 13:07
khurram007 khurram007 is offline
Registered User
 
Join Date: Apr 2007
Posts: 28
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.
Reply With Quote
  #10 (permalink)  
Old 05-09-07, 04:36
georgev georgev is offline
SQL Apprentice
 
Join Date: Jan 2007
Location: hiding
Posts: 8,139
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
You only stop learning when you stop asking questions.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On