Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
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
1  
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

1 Answer 1

up vote 3 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]
share|improve this answer
    
Great answer, thanks! –  Nathan Ridley Dec 28 '11 at 21:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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