如何创建一个批处理,在本地网络上的所有(未知)共享文件夹中搜索特定文件夹? [英] How can I create a batch that searches all (unknown) shared folders on the local network for a specific folder?

查看:222
本文介绍了如何创建一个批处理,在本地网络上的所有(未知)共享文件夹中搜索特定文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有几百个客户端,这些客户端在其自己的本地网络上具有唯一的服务器名称,该客户端托管名为"Installs"的特定文件夹.最终,我要放在一起的是一个批处理,该批处理找到具有所述名称的文件夹,并使用该文件夹中的MSI文件安装在他们的计算机上.服务器名称可以是任何名称,我唯一可以确定的是它将共享该特定文件夹.我已经尝试了多种网络视图,查找,目录,wmic共享的变体..没有这种运气,也没有搜索所有可用网络资源的能力.我当时想我可以进行网络查看> shared.txt,并以某种方式使用其中的名称在这些计算机上搜索安装".我只是茫然,似乎我必须开始解析,这比我高了一点.会有人知道怎么做吗?

We have several hundred clients with unique server names on their own local networks that hosts a specific folder called "Installs". Ultimately what I'm trying to put together is a batch that finds this folder with said name and use an MSI file in that folder to install on their machine. The server name could just be anything, the only thing I know for sure is that it will be sharing out that specific folder. I've tried many variations of net view, find, dir, wmic share.. no such luck, no abilities to search all available network resources. I was thinking I could do a net view > shared.txt and somehow use the names it has in there to search for "Installs" on these machines. I'm just at a loss though, it seems like I'd have to start parsing which is a bit above me. Would anyone have any idea how to do this?

网络视图备注...

Server Name            Remark

 ------------------------------------------------------------------------------- 
 \\TDF-DESK2                                                           
 \\FWM-LAPT                                                            
 \\CAC-VCM                                                             
 \\BNE-DESK                                                            
 \\MAXBETA              Win2008R2 Std - Beta Test Server

推荐答案

这将搜索计算机上可用的每个共享,并搜索第2行中列出的foldername.

This searches each share available to your machine and searches for the foldername listed on line 2.

@echo off
set "folder=foldername"
for /f %%a in ('net view ^|find "\\"') do if not "%%a"=="\\%computername%" (
    echo trying server "%%a"
    pushd "%%a" && (
             for /d /r %%b in (%folder%*) do if /i "%%~nxb"=="%folder%" echo server "%%a" folder "%%b"
             popd
            )
)
pause

以下较早的答案:

在LAN上进行测试-更改foldername*,但将*留在此处.
它应该只回显匹配的path\folders.

Test this on a LAN - change the foldername* but leave the * there.
It should just echo the path\folders that match.

这使用名为repl.bat的帮助程序批处理文件-从以下位置下载: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

This uses a helper batch file called repl.bat - download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat

repl.bat放置在与批处理文件相同的文件夹中,或者放置在路径上的文件夹中.

Place repl.bat in the same folder as the batch file or in a folder that is on the path.

@echo off
net share |repl "^.*(.:\\.*)" "$1" a|repl "  *$" ""|repl "\\  *.*" "\"|repl "^..\\windows.*" "" i >temp.tmp
for /f "delims=" %%a in (temp.tmp) do (
for /d /r "%%a" %%b in (foldername*) do echo "%%b"
)
del temp.tmp
pause

这篇关于如何创建一个批处理,在本地网络上的所有(未知)共享文件夹中搜索特定文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆