Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Delete Text files from a folder

Hi All,

How can i delete all Text Files from a particular folder in my machine by using Qlikview.

Example:

IN my machine D:\Data\TextFiles  folder having for 4 text files. Now i want to delete the files by using the Qlikview functionality.

How can i do it.

Thanks in advance.

Regards

Venkat

1 Solution

Accepted Solutions
rbecher
MVP

Hi Venkat,

try this:

execute cmd.exe /c del *.txt;

- Ralf

Astrato.io Head of R&D

View solution in original post

19 Replies
kaushiknsolanki
Partner Ambassador/MVP

Hi,

    For that you need to search for VBScript code to achieve this, as this is not a part of Qlikview.

    But you can use that code in Qlikview as Qlikview supports VBScript.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
erichshiino
Partner - Master

Hi, If you want to delete files using macro, this is the code : (it will delete only text files in the folder C:\Folder)

sub DeleteFiles

Set filesys = CreateObject("Scripting.FileSystemObject")

   filesys.DeleteFile "c:\Folder\*.txt"

end sub

You can also see it working in the attachment (you need to allow system access to macros)

Hope this helps,

Erich

erichshiino
Partner - Master

If you want to do it from script, this is the code:
EXECUTE del C:\Folder\*.txt /q

On the script window, settings tab (bottom of the screen), you need to mark 'Can execute external program'

Regards,

Erich

Not applicable
Author

Hi Erich,

Thanks for your reply.

Pls can you explain little more clear  on doing through EditScript.

I didn't get you point.

Regards

Venkat

erichshiino
Partner - Master

Hi,

This is a line you should include in your script:

EXECUTE del C:\Folder\*.txt /q

The execute command will send it to windows. It's the same as opening DOS prompt and writing the command there.

Del will exclude .txt files in the folder C:\Folder\

the /q parameter will make this command run quietly (without opening the prompt window or showing messages when it finishes)

Hope it helps,

Erich

Not applicable
Author

Hi Erich,

Sorry for very late reply.

I tried your Script code but generating an error "SCRIPT LINE ERROR".

Pls see the attached document. And update me where i am done wrong.

Regards

Venkat.

rbecher
MVP

Hi Venkat,

try this:

execute cmd.exe /c del *.txt;

- Ralf

Astrato.io Head of R&D
Not applicable
Author

Hi Ralf Becher,

With Edit script it working fine now.

And now i am trying with macro code but it is not deleting the files from folder.

Always it is geneating Else part msgbox i.e; NO FILES TO DELETE. The folder contains Text files also but it is not entering into "if loop".

Pls check the below macro code.

Sub DeleteFiles
Set filesys = CreateObject("Scripting.FileSystemObject")
If filesys.FileExists("D:\TestAllFlatFiles\*.txt") then
filesys.DeleteFile "D:\TestAllFlatFiles\*.txt"
Msgbox("Files Deleted")
Else
Msgbox("No Files to delete")
End If
End Sub

Thanks in Advance.

Regards

Venkat

rbecher
MVP

Hi Venkat,

this will not work. You have to loop over files:

http://groups.google.com/group/microsoft.public.scripting.vbscript/browse_thread/thread/44b57743b25a...

HTH,

- Ralf

Astrato.io Head of R&D