Topics: Developer Forum
Feb 7, 2007 at 3:47 AM
Keith, I'm not sure about the changes to dir.ps1. I think we shouldn't distinguish between hidden and system files, since it is a filesystem-only concept. Moreover, someone interested in hidden files will certainly be interested in the system files as well. By introducing a separate preference, we force people to remember to set two variables just to say "i want to see everything".

The script fails when used on non-filesystem providers (the DirectoryServices for example). Maybe we should call it dirfs or something, since it is really filesystem-oriented, and behaves quite differently than the Get-ChildItem.
Feb 7, 2007 at 1:00 PM
Instead of making a blanket decision like that why not offer 3 options:
-ShowAll (meaning both)
Feb 7, 2007 at 1:35 PM
I made a quick search of my Vista installation, and I have found a very few non-hidden system files or directories. Therefore, you would need both flags set to see most of the hidden/system content. I'm not sure what the benefit of being able to not display ten directories deep in the Windows directory, based on a preference variable would be.
However I'm pretty sure the additional filtering will make the already awfully bad performance even worse, especially on high latency networks and/or in directories with many items.
Feb 7, 2007 at 1:40 PM
Edited Feb 7, 2007 at 1:40 PM
try it yourself

gci -rec -force -ea silentlycontinue |? { $_.Mode -match 's' }
Feb 7, 2007 at 11:35 PM
The main thing is that I don't want to see system files but I do want to see hidden files. This basically how I set up Windows Explorer on my machines. It's a fair point about this not working on non filesystem providers. I should be able to account for this (ie bypass the FileAttributes check if the FileAttributes property doesn't exist).
Feb 8, 2007 at 12:24 AM
OK fixed the issue with non-filesystem providers. I guess I could either way on the extra preference variable. It is just that $home/AppData is marked hidden but not system. If we go back to just one, we might want to rename it to something like PscxDirForcePreference since it would only be used as the parameter to gci -force.
Feb 8, 2007 at 2:40 PM
Well, the PscxDirForcePreference sounds best to me. I measured the performance, and it is really baaaaad :(

[12] » (Measure-Command { Get-ChildItem C:\Windows\System32 | format-table | out-string | out-null }).TotalSeconds
[13] » (Measure-Command { dir C:\Windows\System32 | format-table | out-string | out-null }).TotalSeconds
Feb 8, 2007 at 5:21 PM
Edited Feb 8, 2007 at 5:21 PM

I nearly fell off my chair until I realised that your decimal separator in czechoslovakia is a comma. ;)

- Oisin
Feb 8, 2007 at 5:28 PM
OK grab the latest bits and try this again. I've set the PscxDirHideSystemPreference to $false in the profile. So the performance should be only a bit slower. Note that if you use the -setAttr or -unsetAttr to filter the dir output then it will be significantly slower (like you were seeing). But that seems OK to me because you are asking for dir to do more.

BTW speaking of performance. What's your load time for the PoSH prompt using the PSCX profile? Mine is getting close to 4 seconds. :-(
Feb 9, 2007 at 1:38 AM
Keith, I made some changes, mostly code reorg, removed the global scope pollution and fixed/added -desc parameter on all variants. May I ask you to review it? The perf is quite acceptable now:

[186] » $DebugPreference = 'silentlycontinue'
[187] » $PscxDirForcePreference = $true
[188] » $PscxDirHideSystemPreference = $false
[189] »
[189] » (Measure-Command { gci C:\Windows\System32 | format-table | out-string | out-null }).TotalSeconds
[190] » (Measure-Command { dir C:\Windows\System32 | format-table | out-string | out-null }).TotalSeconds
[191] »
[191] » $PscxDirHideSystemPreference = $true
[192] » (Measure-Command { dir C:\Windows\System32 | format-table | out-string | out-null }).TotalSeconds
[193] »
[193] »
Oisin: hehe :-)))) fyi, czechoslovakia split in 1993 into separate czech and slovak republic.
Feb 10, 2007 at 6:57 AM
OK reviewed the changes. Most of them look good to me although I made a few tweaks to get the behavior I was looking for. I also got rid of the Get-Hashtable function because it wasn't providing much value. What I want was to provide a default sort order for dir, dird, dirs, dirt and dirw. However if the user specifies -sort then their sort parameter completely overrides any default sort order. I also needed to change when $force is set to true. Basically I want to emulate dir /a behavior. Once you specify a set or unset attribute, I want to provide info on every file and not filter anything. The $PscxDirHideSystemPreference is just for the default dir display. I also needed to tweak when we need to add 'system' to $unsetAttr based on the $PscxDirHideSystemPreference. Again I only add this if neither $setAttr or $unsetAttr are specified so that dir gives more predictable results.

BTW what do you guys think of the updated functionality as outlined below?

    -path      : Path(s) to operate on
    -first     : Display only the first specified number of items
    -last      : Display only the last specified number of items
    -combine   : Combine output of multiple paths into a single stream
    -where     : Filter scriptblock to apply to the output
    -sort      : Sort property name(s) or hashtable to apply to output
    -desc      : Modifies the sort parameter to sort in descending order
    -setAttr   : Filter items by those that have the specified attrs set
    -unsetAttr : Filter items by those that have the specified attrs not set
    -wide      : Display directory output in wide format
    -?         : Display this usage information
The possible enumeration values for setAttr and unsetAttr are:
    ReadOnly, Hidden, System, Directory, Archive, Device, Normal, Temporary,
    SparseFile, ReparsePoint, Compressed, Offline, NotContentIndexed, Encrypted
I use dir a lot and even though I like the PoSh "composability" way I also value terseness so having these gci shortcuts are very handy IMO. I especially like stuff like this:

# show me the five newest files in the current dir
dirt -d -f 5  
dir -set ReparsePoint
dir -set archive -unset hidden,system, directory
# show me the five largest files in either . or C:\temp
dirs .,c:\temp -combine -d -f 5 
Feb 13, 2007 at 8:31 PM
Is this still a filesystem:: specific function? I got red error text quite frequently when using it with other providers, so much so that I don't use it anymore. I don't remember the specific errors, I'll double check when I get home.
Feb 13, 2007 at 11:13 PM
no, it should't be filesystem specific. do you have any repro? it seems to me it works both on registry and environment providers
Feb 14, 2007 at 5:26 AM
The only aspect that is file system specific is the -setAttr and -unsetAttr parameters. If you avoid those then it "should" work fine with other providers.
Feb 14, 2007 at 4:38 PM
I noticed that dir.ps1 doesn't seem to pass along -verbose or -debug to the underlying get-childitems call. Should I log this as an issue?
Feb 18, 2007 at 10:26 AM
I've fixed this in addition I added parameters for -filter, -recurse and -force to pass thru to GCI.