How to Delete all files & all folders in a specific directory

Please give me sample .xaml how to Delete all files & all folders frmo a specific directory.
Thanks.

Hey @afrizal

You can check this Existing Thread - How to delete multiple files

Regards…!!
Aksh

Hey @aksh1yadav

It’s only delete all files, but not for folders.
I want it to delete both all files and folders in a specific directory.
Thanks.
Regards,
Afrizal

For Directory Look This - Trouble with invoke method - #3 by aksh1yadav

Regards…!!
Aksh

Here is a detailed article on that :slight_smile:

hi @afrizal
Below line gets all directories ,

Directory.GetDirectories(folderPath)

loop through all directories and delete.Attached the xaml file FYI

Thank You

DirectoryDelete.zip (13.5 KB)

Hello Afrizal,
In this video I do a lot of stuff with Files:

1:10 Download the file and Move the latest file to folders
4:30 Rename files with VB commands
6:00 Move files to do Rename
6:55 Delete files
8:15 Delete only PNG files
8:55 Delete all the files except PNG files
9:55 Move files
11:10 Delete files that are older than 2 weeks
Thanks,
Cristian Negulescu

Hi @afrizal

Keep the below code in Invoke code activity

Microsoft.VisualBasic.FileIO.FileSystem.DeleteDirectory(sourceStr,FileIO.DeleteDirectoryOption.DeleteAllContents)

In the place of sourceStr :- Give the folder or file path that you want to delete

DeleteFilesandFolders.zip (8.4 KB)

1 Like

The code deletes all the folders and files, but in the end I get the error “Invoke Code: Exception has been thrown by the target of an invocation” and the process stops. What is this error due to?

.

Hi @Lynx,

Please find the below XAML file for deleting the files and folders.

DeleteFilesandFolders.xaml (11.5 KB)

Regards,
@90s_Developer

1 Like

Thanks friend

1 Like