|
| |
|
|
xterradane
Posts: 143 From: Mobile, AL USA Status: offline
|
FileSystemObject.CopyFile and Renaming - 10/25/2002 22:03:46
I know I can get a file and rename it using the following code:
Dim oFS
Set oFS=CreateObject(" Scripting.FileSystemObject" )
oFS.CopyFile " E:\My Documents\Gail\Passwords.txt" , _
" E:\My Documents\Gail\Test\NewName.txt"
Set oFS=Nothing
However, I want to be able to name the file by the SystemDate. Any ideas on how to do this. I haven' t been able to find any documentation. Thanks
|
|
|
|
Mojo
Posts: 2431 From: Chicago Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/26/2002 1:02:37
You may need to do something like this:
var = cSTR(now())
var = replace(var, " /" , " -" )
var = replace(var, " :" , " _" )
var = replace(var, " " , " ~" )
Dim oFS
Set oFS=CreateObject(" Scripting.FileSystemObject" )
oFS.CopyFile server.mappath(" t_cart_test.mdb" ) , server.mappath(var &" .mdb" )
Set oFS=Nothing
Basically, I am making a string out of the date/time. Certain characters can cause problems in a file name so you should remove them. Now that you have the string - simple concatenate it to the new file name.
_____________________________
Split Testing Chicago Order Fulfillment Emergency Kits
|
|
|
|
xterradane
Posts: 143 From: Mobile, AL USA Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/27/2002 15:57:57
I don' t believe I can use the Server.Mappath and it is with a text file rather than a database. I might not need to use ASP, but I didn' t know what else to use. This is what I am trying to do: There is a report (Text) which is authomatically created once every hour and it saves to the same file name, thus overwriting the previous hours' data. I need to be able to take the file and have it copied to another directory and saved as the system date, so the reports can be looked at over a period of time. We can' t change the code to the software, so we must add some to it.
|
|
|
|
Mojo
Posts: 2431 From: Chicago Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/28/2002 9:23:28
It should not matter if it is a text file or not. I just happened to use a .mdb file. Text works fine. You don' t have to use server.mappath (why can' t you?). You will need to type in the entire path - you should have no problems once you do that. Joe
_____________________________
Split Testing Chicago Order Fulfillment Emergency Kits
|
|
|
|
xterradane
Posts: 143 From: Mobile, AL USA Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/28/2002 10:33:58
I guess I don' t know what I am doing. I am getting an error on the first Mappath line, it says object required: Server:
var = cSTR(now())
var = replace(var, " /" , " -" )
var = replace(var, " :" , " _" )
var = replace(var, " " , " ~" )
Dim oFS
Set oFS=CreateObject(" Scripting.FileSystemObject" )
oFS.CopyFile server.mappath(" Passwords.txt" ), _
server.mappath(var &" .txt" )
Set oFS=Nothing Any ideas on what I am doing wrong?
|
|
|
|
Mojo
Posts: 2431 From: Chicago Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/29/2002 9:53:55
What is the error? Also, you may want to try keeping it on one line...
_____________________________
Split Testing Chicago Order Fulfillment Emergency Kits
|
|
|
|
xterradane
Posts: 143 From: Mobile, AL USA Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/29/2002 19:46:35
I have tried it on one line as well. I get the same results. The error is as follows: Line 9, Char 2 Error: Object required: ' server' Code: 800A01A8 Source: MS VBScript runtime error
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/29/2002 23:12:49
What is your web server OS? Server is a built-in to asp object that will be available in any MS IIS server.
_____________________________
====== Doug G ======
|
|
|
|
xterradane
Posts: 143 From: Mobile, AL USA Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/30/2002 17:32:21
MS 98. I have developed all my ASP pages using this computer, but I tested it using the personal web server. This is a special thing my boyfriend asked me to develop for his work. So, I am thinking I am doing something wrong with the coding since it is a .vbs file. What do you think? Do I need to point it to the server software built in? I thought it would be able to without coding. I know it is something I just don' t know about. I am not good with understanding how some of this stuff works, esp. networking type things.
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/30/2002 23:16:26
Oh, if you are working with a .vbs file you are not using asp at all. asp is built in to the web server. You will be using the Windows Script Host and you won' t be able to use server.mappath. The rest of mojo' s code should work fine though. Try something like this, changing the paths as necessary:
var = cSTR(now())
var = replace(var, " /" , " -" )
var = replace(var, " :" , " _" )
var = replace(var, " " , " ~" )
Dim oFS
Set oFS=CreateObject(" Scripting.FileSystemObject" )
oFS.CopyFile " c:\mypath\oldfile.txt" , " c:\mypath\" & var &" .txt"
Set oFS=Nothing
_____________________________
====== Doug G ======
|
|
|
|
xterradane
Posts: 143 From: Mobile, AL USA Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 10/31/2002 10:21:39
My results give me this for the file name: (var & ' .txt' ) rather than the system date. It gives me whatever I put on the line. Here' s my new code:
var = cSTR(now())
var = replace(var, " /" , " -" )
var = replace(var, " :" , " _" )
var = replace(var, " " , " ~" )
Dim oFS
Set oFS=CreateObject(" Scripting.FileSystemObject" )
oFS.CopyFile " E:\My Documents\Gail\Passwords.txt" , _
" E:\My Documents\Gail\Test" & var &" .txt"
Set oFS=Nothing This is just boggling my mind. It seems like such an easy thing to do that I am sure it can be done, but I just can' t figure out how.
|
|
|
|
Doug G
Posts: 1189 Joined: 12/29/2001 From: SoCal Status: offline
|
RE: FileSystemObject.CopyFile and Renaming - 11/3/2002 2:11:49
Just a guess, try leaving out the line continuation _ and put the whole copy statement on one line. I don' t know for sure if the line continuation works the same in .vbs files.
_____________________________
====== Doug G ======
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|