[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

For /F search for MP3 files on remote servers

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
LarrySingleton
Asked:
LarrySingleton
3 Solutions
 
Al faCommented:
for /f %%f in (Servers3.txt) do dir %%f /s /a /b > C:\Scripts\MP3.txt

Open in new window

0
 
LarrySingletonAuthor Commented:
Thanks for the quick response, but I'm still getting "%%f is unexpected at this time".
0
 
ThommyCommented:
Please provide your complete batch script to solve the problem...
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LarrySingletonAuthor Commented:
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
 
ThommyCommented:
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
 
Bill PrewCommented:
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
 
LarrySingletonAuthor Commented:
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

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now