Qlik Community

Ask a Question

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Our next Qlik Insider session will cover new key capabilities. Join us August 11th REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
andreyfcdk91
Creator
Creator

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
MVP
MVP

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
MVP
MVP

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

andreyfcdk91
Creator
Creator
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
MVP
MVP

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