Welcome !

 Delete file error

Author Message

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 12/29/2016
  • Status: offline
Delete file error Thursday, December 29, 2016 3:21 PM (permalink)
I am a real novice and have come up against a problem that is driving me nuts - please help!!! I'm not smart enough.
I have a a script that I'm really happy with and I wanted to add a bit of housekeeping at the end that would delete an unwanted file. PROBLEM!
I have condensed the problem here...
 ' strPathFile varaible has been set earlier, in this example lets assume it is set to "C:\Temp\Goyder2.jpg"
 MsgBox strPathFile  'Confirms I have the correct details for a file I want to delete
Dim filesys
 Set filesys = CreateObject("Scripting.FileSystemObject")
 'filesys.DeleteFile ("C:\Temp\Goyder2.jpg")  'this proved my method is correct and worked as expected but it is hard coded
 filesys.DeleteFile (strPathFile) 'this is the line I want to work but it throws an error and fails to delete the file!

I get a "Bad file name or number" error. What am I getting so wrong?
Please help if you can.

    • Total Posts : 2
    • Scores: 0
    • Reward points : 0
    • Joined: 12/29/2016
    • Status: offline
    Re:Delete file error Friday, December 30, 2016 9:56 AM (permalink)
    Turns out my variable which contained the file location was wrapped in quotation marks. This was causing the error when performing the DeleteFile command.
    Stripped the quote marks from the string and voila.
    All good now
      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-2017 ASPPlayground.NET Forum Version 3.9