简体   繁体   中英

Windows Batch File: Looping through Network Shares

I have a classroom network where all of the machines have a shared folder following the same pattern. Each share can be accessed as:

\\\\…\\foo\\bar\\folder

Here, the names foo , bar and folder are fixed, and only the computer name is different.

Eventually I plan to copy files to all of the folders above.

The question is: how do I loop through all of the share names above? In a command shell, I tried:

for %i in (\\\\*\\foo\\bar\\folder) do echo %i

but that's not working for me.

Thanks

    for /f "skip=3" %A in ('net view ^| findstr /v /C:"The command completed successfully"') do Echo %A

Lists all computers turned on. You put %A into your copy command instead of computername, eg

for /f "skip=3" %A in ('net view ^| findstr /v /C:"The command completed successfully"') do dir %A\C$

In a batch file use %%A instead of %A

You could try to use IP address due to classroom network to carry out your function.

example: Your IP range is 192.168.1.2 to 192.168.1.100

for /L %%a in (2,1,100) do (
  if exist \\192.168.1.%%a\foo\bar\folder (
    your command
  )
)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM