任务计划程序有问题运行CMD文件在手动运行时有效(Task Scheduler Having Issues Running CMD file that works when its run manua

编程入门 行业动态 更新时间:2024-10-20 16:29:48
任务计划程序有问题运行CMD文件在手动运行时有效(Task Scheduler Having Issues Running CMD file that works when its run manually)

我有一个脚本删除我的Epson扫描文件夹中的所有文件。 如果我手动运行脚本,它可以很好地工作。 但出于某种原因,如果我在任务调度程序中设置任务,它不会删除文件? 有谁知道为什么会这样?

注意:pclist.txt只是个人电脑名称列表

@echo off for /F %%G in (pclist.txt) do ( pushd "\\%%G\C$\Epson Scans" || exit /B 1 for /D %%I in ("*") do ( rd /S /Q "%%~I" ) del /Q "*" popd )

I have a script to delete all files in my Epson Scans Folder. If I run the script manually it works perfectly. But for some reason if I set up a task in task scheduler it does not delete the files? Does anyone know why this would happen?

Note: pclist.txt is just a list of pc names

@echo off for /F %%G in (pclist.txt) do ( pushd "\\%%G\C$\Epson Scans" || exit /B 1 for /D %%I in ("*") do ( rd /S /Q "%%~I" ) del /Q "*" popd )

最满意答案

你确定文件pclist.txt位于'可能'的\Windows\system32目录中吗?

当作为计划任务运行时,当前目录不一定是以用户身份运行时使用的目录。

实现这一目标的最简单方法是将完整路径放在这些括号内,或者在@echo off下面添加以下行。

IF "%CD%\" NEQ "%~dp0" PUSHD "%~dp0"

Are you sure that the file pclist.txt is located in 'probably' the \Windows\system32 directory?

When run as a Scheduled task the current directory will not necessarily be that used when run as a user.

The easiest way to achieve that is is to put that full path within those parentheses or to add the following line just beneath the @echo off.

IF "%CD%\" NEQ "%~dp0" PUSHD "%~dp0"

更多推荐

本文发布于:2023-07-05 06:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1034403.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   计划   程序   Task   Scheduler

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!