Solved

Put Search results into a CSV file

Posted on 2006-06-09
16
404 Views
Last Modified: 2010-04-03
Is there a way to do a search of local drives and put the result into a csv file?
I want to fild all files on local drives larger than 20mb.
I need to have filename, size, modified, location

0
Comment
Question by:wmannix
16 Comments
 
LVL 10

Expert Comment

by:GuruGary
ID: 16875482
Yes, it can be done.  VBScript or a batch file could probably do it the easiest.  Batch file would use the FSUTIL command to get the list of local drives, then use a DIR command in a FOR /F loop to build your CSV file with %~z for size and %~t for modified timestamp of the file.  I doubt you will find somebody to write the code for 50 points, though.
0
 

Author Comment

by:wmannix
ID: 16876675
It's a fairly important problem for us.  Re-assessed point value.  I'm new to this, and not sure how the whole point thing works.
0
 
LVL 10

Accepted Solution

by:
GuruGary earned 300 total points
ID: 16877366
No problem.  Here is a batch file that should do what you want.  If you are not familiar with batch files, you can use NOTEPAD to create the file.  For example use Start -> Run -> "notepad c:\searchdrives.bat"
Then paste the code below into NOTEPAD, and File -> Save
Then you can browse to your C: drive, and double-click on SEARCHDRIVES.BAT

You can change the SEARCHSIZE and OUTPUT near the top of the file for your desired results.  Note that if the specified OUTPUT file exists when you run this batch file, it will be deleted and replaced with these new results.  Also note that searching entire hard drives can take several minutes depending on the size of the drive and the number of files on the drive.  If you need a different format, or have any questions, just let us know.  This uses format:
Filename,filesize,filedate,filepath


@echo off
setlocal
set SearchSize=20971520
set Output=C:\Results.csv

if exist %Output% del %Output%
for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
   fsutil fsinfo drivetype %%a: | findstr -i fixed && call :SearchDrive %%a
   )
echo Complete.  Results stored in %Output%
goto :EOF

:SearchDrive
echo Searching %1:
for /f "tokens=*" %%d in ('dir %1:\ /s /a-d /b') do if %%~zd GTR %SearchSize% echo %%~nd,%%~zd,%%~td,%%~dd%%~pd >>%Output%
goto :EOF
0
 
LVL 10

Expert Comment

by:stafi
ID: 16877627
here is what you need and more:

http://www.raxco.com/products/diskstate/

0
 
LVL 70

Expert Comment

by:garycase
ID: 16878649
Here's a simple FREE program that will find all files matching your specifications (> 20 MB):
http://www.freebyte.com/disktective/

This one's not free, but does have a free trial version -- and will export to Excel format (as you asked for):
http://www.spadixbd.com/dsm/index.htm
0
 

Author Comment

by:wmannix
ID: 16886284
I'm more apt to go w/ the batch file option so I don't have to install anything on the servers...
I do have one question though:
Is
  for %%a in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
   fsutil fsinfo drivetype %%a: | findstr -i fixed && call :SearchDrive %%a
   )
to identify the local drive letter?  or is that for networked drives?


Thanks for all the rapid responses folks.
0
 

Author Comment

by:wmannix
ID: 16886450
Also....
I just ran the batch job...
I have results.  It's great.  But.  I have no file extensions.  I have the option on in explorer to view them, and system files.  But it doesn't have them in the resultant data.
0
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 
LVL 10

Expert Comment

by:GuruGary
ID: 16889594
Hi, Wmannix.  The FOR loop you asked about is to detect the drive type of each drive letter and only run on local drives (not network).

Sorry about the missing file extensions.  That was an oversight on my part.  Use the following as a replacement for the 2nd FOR loop (just had to add the extension modifier):

for /f "tokens=*" %%d in ('dir %1:\ /s /a-d /b') do if %%~zd GTR %SearchSize% echo %%~nd%%~xd,%%~zd,%%~td,%%~dd%%~pd >>%Output%

If have any other questions, just let us know.
0
 

Author Comment

by:wmannix
ID: 16896870
Not a problem.  Thanks for the extra info.
That worked out perfectly.
This will search all local drives at once.  Correct?

thanks again.
-W
0
 
LVL 10

Expert Comment

by:GuruGary
ID: 16897161
Yes, all local drives in that one command, and the results of all drives go to the same output file.
0
 

Author Comment

by:wmannix
ID: 16897989
thanks!
0
 
LVL 10

Expert Comment

by:GuruGary
ID: 16898157
You're welcome.
0
 

Author Comment

by:wmannix
ID: 16901898
I just ran this on the 1st server.  'FSUTIL' is not recognized as an internal or external command, operable command or batch file.

this is 2000 server.

I have copied fsutil.exe from my XP pro machine to a server (Non Production) and the searchdrives does work.

Will there be adverse affects using fsutil on the 2k box?
0
 
LVL 10

Expert Comment

by:GuruGary
ID: 16902776
I don't think there will be any adverse affects.  The FSUTIL is included with Windows XP, Windows 2003, but MS came out with the utility after the release of Windows 2000.  It should work fine.
0
 

Author Comment

by:wmannix
ID: 16903079
I found a KB article (about 3 min ago) that uses FSUtil from 2k3 or XP to complete a chkdsk function on a 2k server.  So MS supports the use of it in 2k.
Thanks.
0

Featured Post

How to Backup Ubuntu to Amazon S3

CloudBerry Backup offers automatic cloud backup and restoration for Linux. It has both GUI and command line interface (CLI) ensuring its flexibility in use. Find out more

Join & Write a Comment

Lets start to have a small explanation what is VAAI(vStorage API for Array Integration ) and what are the benefits using it. VAAI is an API framework in VMware that enable some Storage tasks. It first presented in ESXi 4.1, but only after 5.x sup…
How to update Firmware and Bios in Dell Equalogic PS6000 Arrays and Hard Disks firmware update.
This video teaches viewers how to encrypt an external drive that requires a password to read and edit the drive. All tasks are done in Disk Utility. Plug in the external drive you wish to encrypt: Make sure all previous data on the drive has been …
This Micro Tutorial will teach you how to reformat your flash drive. Sometimes your flash drive may have issues carrying files so this will completely restore it to manufacturing settings. Make sure to backup all files before reformatting. This w…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now