如何用命令计数共享文件并返回变量?

发布于 2025-01-22 06:50:58 字数 275 浏览 2 评论 0原文

这是我使用的代码。

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

此命令可以在本地环境下正确运行,并返回变量“检查”。 (这意味着%path%中的文件有多少个文件)

但是,当将%路径%设置为共享路径时,变量“检查”始终返回0。

即使我可以使用dir%path%

如何修复代码以从共享文件夹返回变量?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海之角 2025-01-29 06:50:58

执行该搜索的另一种方法是计算不是空白的项目数量。因此,您可以这样执行搜索:

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

我同意斯蒂芬的观点,即您不应将%路径%作为变量。另外,您应该在设定命令周围使用引号。如果这不起作用,我们需要知道路径变量的确切名称和位置。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文