Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Macro: Deleting QVD files with file name mask

Goodevening, experts!

I have simple qvw with working macro, which deletes qvd file, location of which is defined in vPath variable.

I am working now with a solution to delete all files, which have necessary file name mask and only those files, which contain available company name in file name.

So expected result - to delete Data_A_file.qvd, Data_B_file.qvd => as D company isn't included into data model.

Would be grateful for each advice!

Raw data and qvw is in the attachment.

Thanks.

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

Your delete Sub could look like this:

Sub delete

  Set val=ActiveDocument.Fields("Company").GetPossibleValues

  For i=0 to val.Count-1

    File = "Data_" & val.Item(i).Text & "_file.qvd"

    DeleteFile(File)

  Next

End Sub

View solution in original post

3 Replies
petter
Partner - Champion III
Partner - Champion III

Your delete Sub could look like this:

Sub delete

  Set val=ActiveDocument.Fields("Company").GetPossibleValues

  For i=0 to val.Count-1

    File = "Data_" & val.Item(i).Text & "_file.qvd"

    DeleteFile(File)

  Next

End Sub

Anonymous
Not applicable
Author

Thanks.

Also it would be great to have possibility to define File = "Data_" & val.Item(i).Text & "_file.qvd" using file name mask.

So now it uses hard coded position of company id in the name.

Is it possible to use like * symbol in the file name?

petter
Partner - Champion III
Partner - Champion III

Then you should try this:

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery("  Select * from CIM_DataFile where FileName Like '%~%  '  ")

For Each objFile in colFiles

  MsgBox objFile.Name

Next




This snippet is from the Microsoft documentation:


    https://msdn.microsoft.com/en-us/library/aa387236(v=vs.85).aspx