'How to count the shared files with command and return the variable?

Here is the code that I used.

for /f %%a in ('"dir /a:-d /s /b %Path%|find /c ":\""') do set check=%%a

This command can run correctly under the local environment, and return the variable "check". (That means how many files in the %Path%)

However, when setting up the %Path% to shared path, the variable "check" always return 0.

Even I can use dir %Path% successfully.

How to fix the code to return variable from shared folder?



Solution 1:[1]

Another way to perform that search is to count the number of items which are not blank. So, you could perform the search like this:

for /f %%a in ('dir /a:-d /s /b %_myPath% ^|find /c /v ""') do set "check=%%a"

I agree with Stephan that you should not use %PATH% as your variable. Also, you should use quotes around the set command. If this doesn't work, we'd need to know the exact name and location of your path variable.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Qwerty