Results 1 to 9 of 9

Thread: [RESOLVED] Trying to delete a file on the desktop

  1. #1

    Thread Starter
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    186

    Resolved [RESOLVED] Trying to delete a file on the desktop

    This is what I'm doing:
    Code:
    i = FileLen("C:\Users\Jim Allen\Desktop\test.txt")
     If i > 0 Then Kill test.txt
    but it returns a file not found error (53), and yes test.txt is on the desktop.

  2. #2
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,928

    Re: Trying to delete a file on the desktop

    Code:
    i = FileLen("C:\Users\Jim Allen\Desktop\test.txt")
     If i > 0 Then Kill "C:\Users\Jim Allen\Desktop\test.txt"

  3. #3

    Thread Starter
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    186

    Re: Trying to delete a file on the desktop

    Very good point, but the error occurs at
    Code:
    i = FileLen("C:\Users\Jim Allen\Desktop\test.txt")

  4. #4
    Frenzied Member jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    1,928

    Re: Trying to delete a file on the desktop


  5. #5

    Thread Starter
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    186

    Re: Trying to delete a file on the desktop

    My bad!
    The file is not on the desktop, it is being shown on the desktop but not saved to the desktop. I need to delete it from its saved location, thanks for your help.

  6. #6
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    13,820

    Re: [RESOLVED] Trying to delete a file on the desktop

    Why would you use filelen() in this case? Is there a chance the file exists but is 0 bytes? Do you want to not delete the file if it is there but 0 bytes?

    Seems Dir$() would be the wiser choice as it will not throw an error if it does not find the file.

  7. #7

    Thread Starter
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    186

    Re: [RESOLVED] Trying to delete a file on the desktop

    I really didn't think this through before posting, sorry. I have a small program the prints some numbers to a text file, save the file and displays it on the desktop. Then at the users choice they can remove some of those numbers which resaves the file and redisplays it. What I want to do is close the previously opened text file while displaying the new one.

    New question, how do I close a file opened on the desktop.

    Should I post this in a new thread, or is there a way to mark it unresolved?

  8. #8

    Thread Starter
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    186

    Re: Trying to delete a file on the desktop

    I found this: [URL="https://www.vbforums.com/showthread.php?515476-RESOLVED-VB6-Close-window-by-its-window-name[/URL] Post #10

    Seems to work with one major exception, it found the window, but doesn't delete the window. ("Unable to close window!")
    Last edited by Gymbo; Oct 27th, 2021 at 01:34 PM.

  9. #9

    Thread Starter
    Addicted Member Gymbo's Avatar
    Join Date
    Jan 2006
    Location
    The Oregon Coast
    Posts
    186

    Re: [RESOLVED] Trying to delete a file on the desktop

    Commented out the MsgBox and the new txt file replaces it on the desktop, without the added code I would end up with several open text boxes.

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