Jon Z
Jon Z

Reputation: 55

SSIS - Delete Unknown-Name Folder Within A Known Directory

I am writing a SSIS package, and at one point I am working with a certain folder that I know the path for, and need to delete a folder inside that, but I don't know the name (path) of the inner folder.

So for example, I know this path: C:\Known, but there will be a folder inside 'Known' that I would like to delete. Like C:\Known\ Unknown

I can't use a File System Task and delete the unwanted folder, because I don't know the name of the folder, and I can't use a File System Task to delete all the directory contents of 'C:\Known', because it also contains .jpeg files that I need to keep.

Any thoughts? A solution to get the name of the Unknown folder, or delete any folders inside 'C:\Known' is acceptable.

Upvotes: 0

Views: 115

Answers (1)

Bert Wagner
Bert Wagner

Reputation: 881

You can add this code to a Script Task to delete all subdirectories in a path while not deleting any other file types:

foreach (string subdirectoryPath in Directory.GetDirectories(knownPath, "*", SearchOption.AllDirectories))
{
     Directory.Delete(subdirectoryPath);
}

Upvotes: 1

Related Questions