I have a directory that inadvertently had about 1.4 million files generated into it. I want to list just the first, say, 100 items, but without the underlying process trying to read the entire directory contents internally, which causes a very long wait which, at this stage, has been processing for nearly an hour.

How do I do this with Powershell?

link|improve this question

50% accept rate
this question seems to belong to stackoverflow.Maybe last post in stackoverflow.com/questions/1078920/… would be helpful ? – Sergei Dec 28 '11 at 13:09
Is powershell operation not a system administration issue? – Nathan Ridley Dec 28 '11 at 14:11
It is used by system administrators, however your question sounds like a coding task.Nothing wrong to have it here, but I think you are more likely to have question answered among coders. – Sergei Dec 28 '11 at 14:15
Fair enough. It's not a coding task, I just want to delete files. I'm using FastCopy now, which seems to be doing the trick. – Nathan Ridley Dec 28 '11 at 14:30
@Sergei : The last post in that stackoverflow thread implies that you take ALL the content and pipe it through a selection filter. That way, Nathan would have to wait for the 1.4 million file handles to get loaded into memory, just to discard 1.3999 million of them :-) – Mathias R. Jessen Dec 28 '11 at 20:35
show 2 more comments
feedback

1 Answer

up vote 2 down vote accepted

Want the first hundred items in a directory?

@(dir)[1..100]

Only want files?

@(dir -File)[1..100]

Want to skip the first 40 directories and get the next 200?

@(dir -Directory)[41..240]
link|improve this answer
Great answer, thanks! – Nathan Ridley Dec 28 '11 at 21:27
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.