Need a separate csv for each path.

Welcome Forums General PowerShell Q&A Need a separate csv for each path.

This topic contains 7 replies, has 2 voices, and was last updated by

 
Participant
5 years, 1 month ago.

  • Author
    Posts
  • #11307

    Participant
    Points: 0
    Rank: Member

    folder= (Get-Content -Path C:\path.txt)
    $CurrentDate = Get-Date
    $CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hh-mm-ss')

    Get-ChildItem $folder -include *.avi,*.m4a,*.m4p,*.m4v,*.mobi,*.mov,*.doc,*.mp3,*.mp4,*.mpeg,*.mpg,*.VOB,*.wav,*.wma,*.wmv -Recurse |

    select Directory,FullName,CreationTime,Length | Export-Csv -Path "c:\output\mediafiles_$CurrentDate.csv"

    _____________________

    path.txt is below

    c:\

    c:\wondows

    c:\windows\media

    Need a separate csv for each path.

  • #11308

    Participant
    Points: 0
    Rank: Member

    You are using recurse but are specifying different sub folders in your input file. Only need one or the other not both. You could just make one big file which includes the path – then you could sort and filter on that. -Include won't work in the way you are using it
    Why take directory and full name – you have redundant information. I'd take either fullname OR directory and Name

    If you have to have different files per folder then do something like this

    $folders = (Get-Content -Path C:\test2\path.txt)
    $exts = ".txt", ".evt", ".jpg", ".png"

    foreach ($folder in $folders) {
    Get-ChildItem -Path $folder -File |
    where Extension -in $exts |
    select Directory, Fullname, CreationTime, Length |
    Export-Csv -Path "$folder\files.csv" -NoTypeInformation
    }

  • #11309

    Participant
    Points: 0
    Rank: Member

    Thanks Richard. I am checking.

  • #11310

    Participant
    Points: 0
    Rank: Member

    It is providing a single CSV not multiple.

  • #11311

    Participant
    Points: 0
    Rank: Member

    Please post the code you are using and the contents of your path.txt file. I tested my code before posting it and it produces one csv per folder in that folder

  • #11312

    Participant
    Points: 0
    Rank: Member

    Script.
    workflow media {

    Suspend-Workflow
    Checkpoint-Workflow

    $folders = (Get-Content -Path C:\path.txt)
    $exts = “.txt”, “.evt”, “.jpg”, “.png”

    foreach ($folder in $folders) {
    Get-ChildItem -Path $folder -File |
    where Extension -in $exts |
    select Directory, Fullname, CreationTime, Length |
    Export-Csv -Path “$folder\files.csv” -NoTypeInformation
    }

    }
    path.txt
    c:\
    c:\windows
    c:\windows\media

  • #11313

    Participant
    Points: 0
    Rank: Member

    That code won't work in a work flow because work flows don't allow aliases or positional parameters. Try the code as I posted, in a normal script. Once that works for you I can show you how to make the workflow work. Also I don't understand the logic of immediately suspending the workflow

  • #11314

    Participant
    Points: 0
    Rank: Member

    Awesome info Richard. Need resume & suspend during running that script. Please help.

The topic ‘Need a separate csv for each path.’ is closed to new replies.