Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


try to delete a file only when it exists. but this script give me error

 
Logged in as: Guest
arrSession:exec spGetSession 2,7,62704
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> try to delete a file only when it exists. but this script give me error
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 try to delete a file only when it exists. but this scri... - 7/24/2008 3:58:56 AM   
  sd41

 

Posts: 3
Score: 0
Joined: 7/17/2008
Status: offline
Imports System
Imports System.IO
Imports System.Text

Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
Try
Dim sw As StreamWriter = File.CreateText(path)
sw.Close()
Dim path2 As String = path + "temp"

' Ensure that the target does not exist.
File.Delete(path2)

' Copy the file.
File.Copy(path, path2)
Console.WriteLine(
"{0} was copied to {1}.", path, path2)

' Delete the newly created file.
File.Delete(path2)
Console.WriteLine(
"{0} was successfully deleted.", path2)

Catch e As Exception
Console.WriteLine(
"The process failed: {0}", e.ToString())
End Try
End Sub
End Class


line 5
char 8
error: expected identifier
code: 800a03f2


thanks,





 
 
 
Post #: 1
 
 RE: try to delete a file only when it exists. but this ... - 7/24/2008 4:28:03 AM   
  dm_4ever


Posts: 2559
Score: 40
Joined: 6/29/2006
From: Orange County, California
Status: offline
I tried your code....are you sure this file exists

"c:\temp\MyTest.txt"

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to sd41)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [General Forum] >> Other Programming/Scripting Languages >> try to delete a file only when it exists. but this script give me error Page: [1]
Jump to:





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