Export-Csv to a hidden file

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

  • Author
  • #12952
    Profile photo of Gugyivok Krisztian
    Gugyivok Krisztian

    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.


  • #12961
    Profile photo of Richard Siddaway
    Richard Siddaway

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

  • #12965
    Profile photo of Don Jones
    Don Jones

    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
    Profile photo of Bob McCoy
    Bob McCoy

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

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

  • #12979
    Profile photo of Gugyivok Krisztian
    Gugyivok Krisztian

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


You must be logged in to reply to this topic.