Export-Csv to a hidden file

This topic contains 4 replies, has 4 voices, and was last updated by  Gugyivok Krisztian 3 years, 9 months ago.

  • Author
    Posts
  • #12952

    Gugyivok Krisztian
    Participant

    Sorry I couldn't find any topic related to this matter.
    When I try to use export-csv to an already existing, hidden file, I get the error. As you see I use -force switch.
    If I unhide the file it works well.


    Export-Csv : Access to the path 'E:\Users\ao\Desktop\result.csv' is denied.
    At line:1 char:13
    + Get-Process|Export-Csv -Path .\result.csv -force
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OpenError: (:) [Export-Csv], UnauthorizedAccessException
    + FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.ExportCsvCommand

    the original command takes a while to output data to the csv file and I want it to be hidden so I created the file beforehand and hid it, as I couldn't find a switch for export-csv to hide the file when it creates it. there's no point hiding the file, as after export-csv is done, the file gets read and deleted which is happening far more faster.
    I want to hide the file during the output process.
    Any suggestion appreciated.

    Cheers
    Kris

  • #12961

    Richard Siddaway
    Moderator

    Don't think you can – that's the whole point of hidden files

  • #12965

    Don Jones
    Keymaster

    What's the goal in hiding it? To prevent another process from "seeing" it as it is created? In that case, create it in a different folder, and then move it when it's done.

  • #12974

    Bob McCoy
    Participant

    Dynamically create a temp file, and as Don said, move it when you're done.

    PS foo:\> $path = [IO.Path]::GetTempFileName()
    PS foo:\> $path
    C:\Users\bob\AppData\Local\Temp\tmp1CA9.tmp
    PS foo:\> Add-Content -Path $path "foo"
    PS foo:\> mv -Path $path -Destination c:\scripts\gilroy.txt
    PS foo:\> cat C:\Scripts\gilroy.txt
    foo
    PS foo:\>

  • #12979

    Gugyivok Krisztian
    Participant

    Thank you guys. I was afraid there would be no way, but a workaround, but what to do? 🙂

    Cheers

You must be logged in to reply to this topic.