Solved

Put Search results into a CSV file

Posted on 2006-06-09
16
413 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
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

Scale it in WD Gold

With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Robocopy questions 45 172
SBS2008 c:\ drive toosmall 64 63
Macbook Air hard drive missing data storage space mystery 7 29
RAID Configuration 18 5
Sometimes the best way to deal with an infected computer is to boot from external media and run your tools from there.  The reason you may wish to do this really depends on the infection.  Some malware is so recalcitrant that no matter what you do i…
Create your own, high-performance VM backup appliance by installing NAKIVO Backup & Replication directly onto a Synology NAS!
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 tutorial will walk an individual through the process of installing the necessary services and then configuring a Windows Server 2012 system as an iSCSI target. To install the necessary roles, go to Server Manager, and select Add Roles and Featu…

911 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

20 Experts available now in Live!

Get 1:1 Help Now