@t0t0 "and external devices"
http://www.microso
http://ww
http://t
http://
I had a quick look, but I do not have powershell on my machine
Perhaps this is a start - I have never written powershell before
Main Topics
Browse All TopicsHi there,
I just wanted to have a file search on my machine and external device with only the extension like ".xyz".I know i can easily search using dir on each drives but it is not efficient .I just needed an efficient powershell script for a file search with the file extension.
please it is urgent.
Thanks.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
@t0t0 "and external devices"
http://www.microso
http://ww
http://t
http://
I had a quick look, but I do not have powershell on my machine
Perhaps this is a start - I have never written powershell before
Dear Yeniye
I understand your frustration with the DIR command. I must admit it's not the friendliest of commands DOS has to offer and at times, the squiggly-like characters following the command can be so cryptic at first.
Unfortunately, DIR with it's often cryptic bits and pieces that follow it is what we're normally stuck with. Oh, why-oh-why couldn't the makers or DOS allow us to enter commands like this:
LIST ALL FILES WITH AN XYZ EXTENSION NAME
Surely, that can't be rocket-science!
So we're stuck with having to get by with DIR. Here are a few example uses of DIR that I picked up fairly quickly. It might help to jot a few of these down on the inside of your cigarette packet or even on your forearm....
DIR *.* <-- The '*' (star) (SHIFT-8) means 'ANY'. In this case, 'any' filename with 'any' extension.
In other words, EVERY file.
DIR *.TXT <-- Any filename with a TXT extension.
DIR LETTER.* <-- Any file named LETTER (with any extension).
DIR LETTER*.* <-- Any file whose name STARTS with 'LETTER'
All the above commands work in the current folder only, but you can extend these searches to other folders.
DIR C:\*.XYZ <-- All files with an XYZ entension in the root folder of drive C:
DIR C\:temp\*.XYZ <-- All files with an XYZ extension in the folder C:\temp\
DIR /S C:\*.XYZ <-- All files with an XYZ extension STARTING in root folder of drive C:....
and all sub-folders extending from the root folder of drive C:
In other words - the WHOLE of drive C:
Hmmm.... I can understand now why we don't use plain English... Wow, imagine having to type that in every time we want to search the drive.
Finally, your system may support the following:
DIR /S C;\*.XYZ D:\*.XYZ
This will search your whole drives - both C: and D:. Wow... I'm not even going to try putting that into words!!
I hope some of that helps you get by for the moment but please remember, it gets easier the more you use it. And of course, when you're ready to know more, just enter the following command:
DIR /?
which will display DIR's help pages giving many more options.
But take note, you don't need to know it all at once - so take your time and learn just waht you need to get by for now.
Good luck.
Oh, by the way, the output from DIR can be saved to a file. The advantage of this is that you can then open the file and browse through the list of filenames. Here's how it's done:
DIR /S c:\*.xyz d:\*.xyz >list.txt
The '>list.txt' at the end of the command tells DIR to output it's results to a file named LIST.TXT instead of diaplaying it's output on the screen.
Hi,
Here is a Powershell script that you can use that scans your computer for drives (note network shares) and saves the filename and path into a file (and shows them on the console).
Its easy to modify this script if you want to do other things with each file. Each file is saved as a FileInfo object into $files, so you can get size, dates etc as well.
Change the variable at the top named $filter to search for different file extensions like "*.txt" or anything else
Good luck!
/ Mikael
I can simplify the script above a bit :)
Note that no matter what we do here we're not altering the underlying algorithm, efficiency is not impacted (depending on how you define that). Also note that "dir" in PowerShell is an alias for Get-ChildItem, so by using Get-ChildItem you are using "dir".
Chris
Select-Object will do that, although it would take a bit more to make it a sentence. Might want to substitute FileName for Path here, more appropriate for searches.
...
Select-String -Pattern "string to search for" -path $_.fullname | Select-Object FileName, Pattern, LineNumber
...
Drifting away from the original question though...
Chris
.NET if you ask me, WMI is much heavier in my experience. PowerShell uses .NET with only a minor overhead for the Shell. Notice that Get-Item and Get-ChildItem give you System.IO.FileInfo and System.IO.DirectoryInfo objects.
To improve beyond that you'd have to look at the APIs but that's going to be C++ or equivalent.
Excluding folders is fine, except we'd have to write our own recursion. You have to love that the "Exclude" parameter carries a note:
"This parameter does not work properly in this cmdlet."
Fun :)
Anyway, potential implementation of that below. The Pattern parameter and Exclude parameter are Regular Expressions which makes it rather complex, but I quite like it :)
Exclude is optional, you can just leave it off, the other two have default values.
Chris
Thank you for the comment regarding my explanation of the DIR command. Funnily enough, I re-read it (since receiving your comment) and I must admit (with a bit of spit and polish) it does sound quite beginner-friendly.... something I suppose we more experienced DOS user forget how to relate.
Thank you anyway.
By the way, I'm not used to being treated nicely by moderators so this is a first.
Business Accounts
Answer for Membership
by: t0t0Posted on 2009-09-07 at 00:13:04ID: 25273189
You say:
"i can easily search using dir on each drives but it is not efficient"
Firstly, you say you can "easily" search using DIR - obviously, that's what DIR was designed for!
Then you say, "it is not efficient" - what do you mean 'it is not efficient'? In what way?
DIR is the proper tool for what you have described above. To search for all files with just the extension ".XYZ" enter the following DIR command:
DIR *.xyz
It's as easy as that. And then your DOS will display all your files with an '.xyz. extension.
So, how much more efficient do you want DIR to be?
To get a list of all options supported by DIR, enter the following command:
DIR /?