?
Solved

For /F search for MP3 files on remote servers

Posted on 2011-02-11
7
Medium Priority
?
471 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 5

Assisted Solution

by:Al fa
Al fa earned 300 total points
ID: 34874209
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
ID: 34874414
Thanks for the quick response, but I'm still getting "%%f is unexpected at this time".
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34875616
Please provide your complete batch script to solve the problem...
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:LarrySingleton
ID: 34875644
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 500 total points
ID: 34876101
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 56

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34879976
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
ID: 34889198
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 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