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

Author Message
sd41

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 7/17/2008
  • Status: offline
try to delete a file only when it exists. but this script give me error Thursday, July 24, 2008 4:58 AM (permalink)
0
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,
 
 
 
 
 
 
 
#1
    dm_4ever

    • Total Posts : 3687
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: try to delete a file only when it exists. but this script give me error Thursday, July 24, 2008 5:28 AM (permalink)
    0
    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
     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • 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
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9