Solved

For /F search for MP3 files on remote servers

Posted on 2011-02-11
7
468 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
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
Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

 

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 125 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 54

Accepted Solution

by:
Bill Prew earned 125 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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