Home > Enterprise >  How to count the shared files with command and return the variable?
How to count the shared files with command and return the variable?

Time:04-20

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?

CodePudding user response:

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.

  • Related