-2

Let's say I have a list of files (files.txt), which looks like:

\\myshare\file1
\\myshare\file2
\\myshare\file3

How is it possible to check via a batch script (windows) to check if those files exist and output this? I tried with if exists \\path\file, but it always tells me that the path can not be used syntactically at that point.

Peter
  • 103
  • 5

2 Answers2

1

This is a complete script. It can be modified to use with other stuff

@echo off
for /f "tokens=*" %%s in (list.txt) do (
 if exist %%s (
  echo %%s found
  echo %%s >> sharesfound.txt
 ) else (
  echo %%s NOT found
  echo %%s >> sharesmissing.txt
 )
)
Peter
  • 103
  • 5
Vitas
  • 157
  • 1
  • 8
  • 24
0

Based on the format of your path, I think that you're referring to SMB: in that case, either you can mount the share (eg. with mount.cifs) and check as if it's a local file, or you can use smbclient to check if the file exist remotely:

smbclient //host/share -U username -c "ls filetocheck"

The result will be in $?, and it will be zero if file exists, 1 otherwise.

On Windows, you can use if exist \\server\share goto label (actually, you can issue any CMD command instead of goto)

  • Please check my question, I was asking for a batch solution (windows). Thanks for your effort though! – Peter May 04 '18 at 10:14
  • Sorry I don't know why I was so certain that you were asking for Linux. However, I updated my answer :-) –  May 04 '18 at 22:52
  • I guess it should be `if exist` instead of `if exists`. – Peter May 07 '18 at 12:04