/build/static/layout/Breadcrumb_cap_w.png

Custom action to delete files and folders

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")

ProgramFilesx86=WshShell.ExpandEnvironmentStrings("%PROGRAMFILES(x86)%")

path=ProgramFilesx86 & "\avk\RPAVK\*"
testpath="C:\temp\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

Answers (4)

Posted by: anonymous_9363 8 years ago
Red Belt
1
>I had to know that using the MSI table?
Did you read the article I linked to?

Columns

FileKey
Primary key used to identify this particular table entry.
Component_
External key the first column of the Component table. This field references the component that controls the file to be removed.
FileName
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
Posted by: anonymous_9363 8 years ago
Red Belt
0
- '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.

Comments:
  • 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. - Agathorn 8 years ago
Posted by: anonymous_9363 8 years ago
Red Belt
0

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

path=Chr(34) & ProgramFilesx86 & "\avk\RPAVK" & Chr(34)

Comments:
  • 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? - Agathorn 8 years ago
  • 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! - Agathorn 8 years ago
Posted by: anonymous_9363 8 years ago
Red Belt
-1
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)

Comments:
  • Double quotation. I didn´t get it to work anyway. Maybe I did it wrong then. What should I type? - Agathorn 8 years ago
 
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