Solved

For /F search for MP3 files on remote servers

Posted on 2011-02-11
7
462 Views
Last Modified: 2012-05-11
Trying to read through a text file to search remote servers(Win2K3/Win2K8) for *.mp3 items and output to txt (CSV would be even better!).  The text file is C:\Scripts\Server3.txt.  I want to search the D:\Data directories on all servers.  What I have so far is returning error "%%a is unexpected at this time":

FOR /F %%a IN (Servers3.txt) DO DIR /s *.mp3 >>C:\Scripts\MP3.txt

From researching, It appears I may need setlocal enableextensions and/or enabledelayedexpansion.

Also unclear whether it is more efficient to have the text file just read server name(server1) or the network path(\\server1\Data).  

Thanks  : )
0
Comment
Question by:LarrySingleton
7 Comments
 
LVL 5

Assisted Solution

by:Ali Fakoor
Ali Fakoor earned 75 total points
Comment Utility
for /f %%f in (Servers3.txt) do dir %%f /s /a /b > C:\Scripts\MP3.txt

Open in new window

0
 

Author Comment

by:LarrySingleton
Comment Utility
Thanks for the quick response, but I'm still getting "%%f is unexpected at this time".
0
 
LVL 19

Expert Comment

by:Thommy
Comment Utility
Please provide your complete batch script to solve the problem...
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:LarrySingleton
Comment Utility
The batch script I attempted was from Ali listed directly under my question:

for /f %%f in (Servers3.txt) do dir %%f /s /a /b > C:\Scripts\MP3.txt

Servers3.txt just lists Server names.

I'll be glad to post whatever additional information you might need...

0
 
LVL 19

Assisted Solution

by:Thommy
Thommy earned 125 total points
Comment Utility
Error occurs if you start it directly from the command prompt with double "%" like "%%f"!!!

To start it from the command prompt correctly, always omit the first "%":
for /f %f in (Servers3.txt) do dir %f /s /a /b > C:\Scripts\MP3.txt


If you use the command in a batch file, you need double "%":
for /f %%f in (Servers3.txt) do dir %%f /s /a /b > C:\Scripts\MP3.txt


SearchMP3s.cmd
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 125 total points
Comment Utility
How about something like this saved to a BAT file?

@echo off
REM Process each line (server name) from server text file
for /F %%A in (Servers3.txt) do (
  REM Find all MP3 files on this server and report it
  for /F "tokens=*" %%B in ('dir /s /a-d /b \\%%A\Data\*.mp3') do (
    echo %%A,%%B>>C:\Scripts\MP3.csv
  )
)

Open in new window

~bp
0
 

Author Comment

by:LarrySingleton
Comment Utility
I am increasing points and accepting all solutions as Ali provided initial help, but didn't respond to error, Thommy explained the error,but also billprew went on to do the export to CSV.  I am dividing points to Ali, Thommy and billbrew 75/125/125

Thanks to all for your help.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 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

8 Experts available now in Live!

Get 1:1 Help Now