File Deletion from Unknown Folders

~OSD~ 2,131 Reputation points
2020-12-16T10:59:42.25+00:00

Hi,

I have a root directory at N:\DemoLab with following directory structure of known folders (Months,Years,Weeks) and unknown folders (DynamicName, RandomName etc.)

48688-image.png

DemoFile.txt is available under all these sub-directories (regardless if it's dynamically folders or manually created).

Can we check parent directory path N:\DemoLab and search all folders and remove DemoFile.Txt if found in VB.net?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,644 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 114.2K Reputation points
    2020-12-16T11:06:53.877+00:00

    This seems to work too:

    Dim r As New DirectoryInfo("N:\DemoLab")
    
    For Each f In r.EnumerateFiles("DemoFile.txt", SearchOption.AllDirectories)
        f.Delete()
    Next
    

0 additional answers

Sort by: Most helpful