Author Posts

February 5, 2014 at 1:05 am

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

February 5, 2014 at 8:07 am

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

February 5, 2014 at 9:48 am

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.

February 5, 2014 at 12:45 pm

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:\>

February 6, 2014 at 12:50 am

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

Cheers