Script to check if the specific subfolder exist

This topic contains 1 reply, has 1 voice, and was last updated by  Parth Gandhi 2 months ago.

  • Author
    Posts
  • #96606

    Parth Gandhi
    Participant

    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

    Parth Gandhi
    Participant

    I was able to get it using fix path.

You must be logged in to reply to this topic.