Need a separate csv for each path.

This topic contains 7 replies, has 2 voices, and was last updated by  Biswajit 3 years, 9 months ago.

  • Author
    Posts
  • #11307

    Biswajit
    Participant

    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

    Richard Siddaway
    Moderator

    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

    Biswajit
    Participant

    Thanks Richard. I am checking.

  • #11310

    Biswajit
    Participant

    It is providing a single CSV not multiple.

  • #11311

    Richard Siddaway
    Moderator

    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

    Biswajit
    Participant

    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

    Richard Siddaway
    Moderator

    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

    Biswajit
    Participant

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

You must be logged in to reply to this topic.