Take the 2-minute tour ×

I have two files functions.txt and functions.ps1.

At the PS command prompt, when I press tab in the directory, the first choice that comes up is "functions.txt".

However, if I type "del " and then press tab, the first choice that comes up is "functions.ps1".

This appears to be consistent.

Is there some logic behind this, is it coincidence, or is it evil imps trying to trick me into deleting the wrong file?

share|improve this question
I created a folder with your files names and if I press tab it does nothing... If I type fun then press tab I get functions.ps1. If I type del and hit tab I also get functions.ps1. So I couldn't replicate. –  Andy Arismendi Feb 22 '12 at 22:50
You have to create functions.txt first. –  Andrew J. Brehm Feb 23 '12 at 8:22
add comment

2 Answers

If you run:

gci | sort

On a directory, you'll see that it sorts characters, (., $, !, etc) A-Z & a-z, as best I can tell,

Shell> .\ **TAB**

on that directory is just gci | sort in that order (ignoring characters until the end).

I also assume it sorts filename first then extension. So for your example, functions.ps1 comes before functions.txt. I see the same behavior with del TAB, or just .\ TAB

This seems consistant with the following example directory of files:

Mode                LastWriteTime     Length Name
-a---         2/10/2012   2:51 PM          0 foo1
-a---         2/10/2012   2:52 PM          0 foo1.ps1
-a---         2/10/2012   2:51 PM          0 foo2
-a---         2/10/2012   2:51 PM          0 foo2.ps1
-a---         2/10/2012   2:52 PM          0 foo2.txt
share|improve this answer
Maybe I am missing something but I know that. It doesn't explain why "functions.txt" came up first when pressing tab just after the prompt while "functions.ps1" came up first when pressing tab after typing "del ". –  Andrew J. Brehm Feb 10 '12 at 22:46
add comment

The answer appears to be that tab completion really does use two different algorithms to decide which file comes first, depending on situation.

In this examples, the file "ab" is created before the file "aa" and tab completion on "a" (third line) brings up "ab" (the file created first).

PS P:\> echo hello > ab

PS P:\> echo hello > aa

PS P:\> .\ab

But tab completion on "a" after "del " does this:

PS P:\> del .\aa

However, creating the files the other way around gives this result:

PS P:\> echo hello > aa

PS P:\> echo hello > ab

PS P:\> .\aa

And tab completition on "a" after "del " also shows "aa":

PS P:\> del .\aa
share|improve this answer
add comment

Your Answer


