Script to check if the specific subfolder exist

Welcome Forums General PowerShell Q&A Script to check if the specific subfolder exist

This topic contains 1 reply, has 1 voice, and was last updated by

 
Participant
11 months ago.

  • Author
    Posts
  • #96606

    Participant
    Points: 0
    Rank: Member

    Hi Team,
    I am writing a script which checks if a specific sub-folder exists in the list of folders and if so get the list of files older than 2 days from that sub-folder. Below is my folder structure and script. however the Test-path condition always returns false and code inside it doesn't gets executed.

    Dir Structure:
    f:\test\123\Avengers
    f:\test\123\Justiceleague
    f:\test\456\Avengers
    f:\test\456\Justiceleague
    f:\test\789\Avengers
    f:\test\789\Justiceleague

    SCript:

    $folder = gci -Path F:\test\
    foreach ($f in $folder)
    {
    foreach ($i in gci $f.FullName)
    {
    $i.FullName
    # check if the there is a folder called Avengers
    if (Test-Path ($i.FullName -contains 'Avengers'))
    {
    write-host " Avengers folder exist"
    Get-ChildItem -Path $i.FullName -File | Where lastwritetime -lt (Get-Date).AddDays(-2)
    }
    }
    }

  • #96608

    Participant
    Points: 0
    Rank: Member

    I was able to get it using fix path.

The topic ‘Script to check if the specific subfolder exist’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort