Results 1 to 5 of 5

Thread: How to delete a file in vb.net

  1. #1
    Join Date
    May 2009
    Posts
    735

    How to delete a file in vb.net

    Hi,
    I want a way to delete a file in vb.net. I have folder which includes some useless temp file. What I am doing is trying to take a backup of the entire directory. It has several webpages hyperlinked to each other. I want a quick and easy way to delete a file. Also what is the way to copy and move the folders. Thanks in advance.

  2. #2
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How to delete a file in vb.net

    It is very handy to delete a file in vba. You can also remove the entire folder if do not required. Here I will recommend you to use VBA Kill statement. The parameter here is kill path & filename. But kill statement cannot delete read only files. The sample code is as follows :
    Code:
    Dim KillFile As String
    KillFile = "c:\temp\temp.doc"
    'Check that file exists
    If Len(Dir$(KillFile)) > 0 Then
        'First remove readonly attribute, if set
        SetAttr KillFile, vbNormal
        'Then delete the file
         Kill KillFile
    End If

  3. #3
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How to delete a file in vb.net

    If you got the proper syntax then it quiet simple to copy or move folders and f file to different location in vb.net. The VBA Name and FileCopy function are used here. By this you can either move the file and folder or create a copy of files and folders in a desired location. See the codes -
    Code:
    Sub Copy_One_File()
        FileCopy "C:\Users\SourceFolder\text.xls", "C:\Users\DestFolder\text.xls"
    End Sub
    
    Sub Move_Rename_One_File()
    'You can change the path and file name
        Name "C:\Users\SourceFolder\text.xls" As "C:\Users\DestFolder\text.xls"
    End Sub

  4. #4
    Join Date
    May 2008
    Posts
    2,012
    Just give the kill function to delete the folder. For eg. give Kill C:\folder. It remove the folder permanently. You will have to ensure here the Kill path and file name. Otherwise the syntax will not work properly.Then to copy use the File copy function. Determine the name path and file name as new path and file name. The file will copied to the desired location.

  5. #5
    johnspells Guest

    Re: How to delete a file in vb.net

    That was amazing I was not aware about kill function in vb.net, I was just thought that it will have remove and delete option. I was just wondering that can we also use the delete/remove function at the place where we had used kill function.I think that for addition or remove if loop is very helpful. Good job,keep doing it.

Similar Threads

  1. Replies: 3
    Last Post: 21-03-2012, 09:10 AM
  2. cannot delete file -- cannot read from source file or disk
    By Amitgujaran in forum Windows XP Support
    Replies: 3
    Last Post: 11-11-2010, 09:55 PM
  3. Can't delete 0 byte file, with no file type
    By Adele2 in forum Windows XP Support
    Replies: 8
    Last Post: 15-12-2009, 12:33 PM
  4. Cannot delete file with no name disk file
    By Shanbaag in forum Windows Software
    Replies: 4
    Last Post: 17-08-2009, 02:14 AM
  5. XP: Cannot delete file: Cannot read from the source file or disk.
    By iexplorer0726 in forum Operating Systems
    Replies: 0
    Last Post: 10-09-2007, 05:07 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,570,609.31131 seconds with 17 queries