Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript Quest about obj.TextFile.SaveAs 1

Status
Not open for further replies.

chiplarsen

IS-IT--Management
Jan 8, 2004
87
US
I am trying to do something that I am sure is simple, but I have not work with VBScript much at all. I want to open a text file in one directory and save as to another directory with a new name. When I run this code from a cmd prompt, I do not get an error, it just executes and does nothing in reference to the code. Can someone point me in the right direction? Thank you for your help.
Code:
 On Error Resume Next

  strMonth=Month(DateAdd("d",-1,Date))
  If Trim(Len(strMonth))<2 Then strMonth="0"&strMonth End If

  strDay=Day(DateAdd("d",-1,Date))
  If Trim(Len(strDay))<2 Then strDay="0"&strDay End If

  strFileNameExt=Year(DateAdd("d",-1,Date))&strMonth&strDay

'***** Open Text File *****
  Const ForWriting = 2
  Set objFSO = OpenObject("Scripting.FileSystemObject")
  Set objTextFile = objFSO.OpenTextFile ("C:\PERSELOG\PERSE.TXT")
'*****

'***** Save/close TXT File *****
 objTextFile.SaveAs("C:\PERSELOG\PERSEBK\PERSE-"&strFileNameExt&".TXT")  
 Set objTextFile=Close
'*****
 
With ASP you can do this:
Code:
<% 
    set fso = CreateObject("Scripting.FileSystemObject") 
    fso.MoveFile "c:\oldname.txt", "c:\newname.txt" 
    set fso = Nothing 
%>

 
chiplarsen said:
When I run this code from a cmd prompt, I do not get an error, it just executes and does nothing in reference to the code.
Remove the "On Error Resume Next" line!

That line suppresses all errors without trapping, or even displaying them. The only valid use for "On Error Resume Next" is to error trap a line of code, which should then be immediately followed with "On Error Goto 0" to allow errors to be thrown again. For example:

Code:
On Error Resume Next
[i]do something[/i]
If Err.Number <> 0 Then
   'handle error
End If
On Error Goto 0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top