none
List of Folders where a file does NOT exist RRS feed

  • Question

  • The below code will give me a list of directories where a file DOES exist, which I use for a different purpose.  

    $Dirs=(Get-Item C:\CSData\*\DidLogOn.txt).Directory.Name

    I've got a new problem where I need to get a list of directories where a file DOES NOT exist.  I thought I could change the above code, by first changing the DidLogOn.txt to a file that will be in every directory and then add an exclusion as shown below, but this returns all directory names.

    $Dirs=(Get-Item C:\CSData\*\login.fdl -Exclude "C:\CSData\*\taxtbl2020.db").Directory.Name

    C:\CSData has 400+ sub-directories and I need a list of the directories where a file doesn't not exist.  In my example above, I need a list of directories where taxtbl2020.db does not exist.

    Thanks
    Kevin

    Friday, January 24, 2020 11:26 AM

Answers

  • So I looked at the compare-object and came up with the below, which gives me the desired results:

    $Dir1=(Get-Item C:\CSData\*\login.fdl).Directory.Name
    $Dir2=(Get-Item C:\CSData\*\taxtbl2020.db).Directory.Name
    
    $Dirs = Compare-Object $Dir1 $Dir2
    

    • Marked as answer by bakerkr94 Friday, January 24, 2020 1:29 PM
    Friday, January 24, 2020 1:29 PM