Results 1 to 11 of 11

Thread: Problem to kill file!

  1. #1

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Question Problem to kill file!

    I want to delete a file using kill but I can only delete the file in c:\test.dat directory. When I choose a file in for example c:\Data\test.dat the code is not working and an error message saying "File path not found" appear. Why?

    Here is my vb file I'm working at. Thanks in advance!
    Attached Files Attached Files

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Problem to kill file!

    VB Code:
    1. Text1.Text = Dir1.Path & [B]"\"[/B] & File1.FileName
    you should always step through your code and debug.print variables, especially things like file paths. you would have found this error easily.

  3. #3
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    Re: Problem to kill file!

    Quote Originally Posted by Bearnerd
    I want to delete a file using kill but I can only delete the file in c:\test.dat directory. When I choose a file in for example c:\Data\test.dat the code is not working and an error message saying "File path not found" appear. Why?

    Here is my vb file I'm working at. Thanks in advance!

    Am I to assume that your problem isn't a Windows Security Issue? Also most of the people here can't unzip a RAR files only ZIP files.
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  4. #4

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to kill file!

    Thanks bush its working. But now after I deleted the file, is there any way to get the file again in vb? I want to undo the delete, is it possible?

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Problem to kill file!

    I'm not sure if there's an easy way. If you notice Kill doesn't send the file to the recycle bin, it deletes it outright.

    Perhaps you should send any files to a temporary location from which you can easily recover them, and then delete the whole folder when your program exits.

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Problem to kill file!

    Quote Originally Posted by Bearnerd
    Thanks bush its working. But now after I deleted the file, is there any way to get the file again in vb? I want to undo the delete, is it possible?
    Using Kill, no you can not undo it.

    However, you can programmatically send your file to the recycle bin if you want, and recover it from there if necessary.

  7. #7

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to kill file!

    So better send the file into recycle bin so I can get the file whenever I need it again. How can this be done in vb? Using API or how?

  8. #8

  9. #9

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to kill file!

    Yup thanks bush. I've been searching for API for this. Another question, how can I delete a folder and the entire contents in it?

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Problem to kill file!

    The quickest and easiest way is to use the FileSystemObject. Set a reference to the Microsoft Scripting Runtime.
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim fsoFolder As New FileSystemObject
    3. fsoFolder.DeleteFolder "c:\Data\", True
    4. End Sub

  11. #11

    Thread Starter
    Hyperactive Member Bearnerd's Avatar
    Join Date
    Apr 2006
    Location
    Malaysia
    Posts
    290

    Re: Problem to kill file!

    Many thanks Hack and Bush!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width