Scripting Question

Custom action to delete files and folders

06/11/2015 4533 views
I want to delete files and folders in a CustomAction (and I dont know the names of the files and folder) and I´m trying to write a vbscript for it.
I have gotten the script to work if the folder is located under C:\temp (see example below). But it doesn´t work when trying to delete under C:\Program Files (x86)\...
I think I have path corretly entered, but I can´t see why it doesn´t work so I guess the problem is with the path anyhow.

On Error Resume Next
Dim objFSO
Set WshShell = CreateObject("Wscript.Shell")


path=ProgramFilesx86 & "\avk\RPAVK\*"

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFolder(path), TRUE
objFSO.DeleteFile(path), TRUE

objFSO.DeleteFolder(testpath), TRUE
objFSO.DeleteFile(testpath), TRUE
0 Comments   [ + ] Show comments


Community Chosen Answer

>I had to know that using the MSI table?
Did you read the article I linked to?


Primary key used to identify this particular table entry.
External key the first column of the Component table. This field references the component that controls the file to be removed.
This column contains the localizable name of the file to be removed. If this column is null, then the specified folder will be removed if it is empty. All of the files that match the wildcard will be removed from the specified directory.

The above has my emboldening and underlining. Use '*' as the wildcard
Answered 06/11/2015 by: anonymous_9363
Red Belt

All Answers

- 'path' can't both be a folder and a file;
- the trailing backslash and the asterisk are spurious

Either find a script that recurses through a folder tree performing an action or, better, use the RemoveFile table in the MSI.
Answered 06/11/2015 by: anonymous_9363
Red Belt

  • I don´t get it. It works with "testpath". Why shouldn´t it work with "path" ? Its just a variable with a path saved in it.

Any reason why you're not using the MSI table?

path=Chr(34) & ProgramFilesx86 & "\avk\RPAVK" & Chr(34)
Answered 06/11/2015 by: anonymous_9363
Red Belt

  • Thanks! I'll try it out! I don´t know how many files and folders there are under there or their names. If I remember things correctly I had to know that using the MSI table?
  • Still didn´t get it to work. Something wrong with the script. I hade to solve it asap so I just wrote a .cmd-file that I wrapped with the MSI instead. I´ll give it another shot when I have time!
Kludge, kludge, kludge...

Using your knowledge of Windows paths and permitted characters, ask yourself "What's the singlemost stand-out difference between 'C:\TEMP' and 'C:\Program Files (x86)'?"

Hint: look up Chr(34)
Answered 06/11/2015 by: anonymous_9363
Red Belt

  • Double quotation. I didn´t get it to work anyway. Maybe I did it wrong then. What should I type?
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ