Batch file 自动当前批处理脚本

Batch file 自动当前批处理脚本,batch-file,utorrent,Batch File,Utorrent,我根据我找到的另一个脚本为自己写了一个脚本,我很难弄清楚为什么它不起作用 它的工作原理是,一旦torrent完成下载,它就会运行脚本并获取torrent上的标签。为了测试,我下载了一首带有音乐标签的歌曲。 当它到达点:copyfile时,它不会将其移动到正确的目录中。它没有移动到F:\Completed Torrents\Music,而是移动到F:\Completed Torrents 有人能指出我遗漏了什么吗?因为我已经看了三遍了,这让我发疯了。脚本如下 @echo off title Lia

我根据我找到的另一个脚本为自己写了一个脚本,我很难弄清楚为什么它不起作用

它的工作原理是,一旦torrent完成下载,它就会运行脚本并获取torrent上的标签。为了测试,我下载了一首带有音乐标签的歌曲。 当它到达点:copyfile时,它不会将其移动到正确的目录中。它没有移动到F:\Completed Torrents\Music,而是移动到F:\Completed Torrents

有人能指出我遗漏了什么吗?因为我已经看了三遍了,这让我发疯了。脚本如下

@echo off
title Liam's torrent-file script
rem Parameter usage: fromdir torrent-name label kind [filename]
rem corresponds to uTorrents flags: %D %N %L %K %F 
echo *********************************************
echo Run on %date% at %time%

set fromdir=%1
set name=%2
set label=%3
set kind=%4
set filename=%5
set savepartition="F:\Completed Torrents"
set winrar="C:\Program Files (x86)\WinRAR\WinRAR.exe"
set torrentlog="F:\Torrent Scripts\logs\torrentlog.txt"
set handledlog="F:\Torrent Scripts\logs\handled_torrents.txt"
set errorlog="F:\Torrent Scripts\logs\ErrorLog.txt"
set label_prefix=""

echo Input: %fromdir% %name% %label% %kind% %filename%

rem Check if the label has a sub label by searching for \
if x%label:\=%==x%label% goto skipsublabel
rem Has a sub label so split into prefix and suffix so we can process properly later
echo sub label
for /f "tokens=1,2 delims=\ " %%a in ("%label%") do set label_prefix=%%a&set label_suffix=%%b
rem add the removed quote mark
set label_prefix=%label_prefix%"
set label_suffix="%label_suffix%
echo.prefix  : %label_prefix%
echo.suffix  : %label_suffix%
goto:startprocess

:skipsublabel
echo Skipped Sub Label
goto:startprocess

:startprocess
echo %date% at %time%: Handling %label% torrent %name% >> %handledlog%

rem Process the label
if %label%=="Movies" goto known
if %label%=="Music" goto known
if %label_prefix%=="TV" goto TV


rem Last resort
rem Double underscores so the folders are easier to spot (listed on top in explorer)
echo Last Resort
set todir=%savepartition%\Unsorted\__%name%
if %kind%=="single" goto copyfile
if %kind%=="multi" goto copyall
GOTO:EOF

:known
echo **Known Download Type - %label%
set todir=%savepartition%\%label%\%name%
echo todir = %todir%
GOTO:process

:TV
echo **Known Download Type - %label%
set todir=%savepartition%\%label_prefix%\%label_suffix%
echo todir = %todir%
GOTO:process

:process
rem If there are rar files in the folder, extract them.
rem If there are mkvs, copy them. Check for rars first in case there is a sample.mkv, then we want the rars
if %kind%=="single" goto copyfile
if exist %fromdir%\*.rar goto extractrar
if exist %fromdir%\*.mkv goto copymkvs
if %kind%=="multi" goto copyall
echo Guess we didnt find anything
GOTO:EOF

:copyall
echo **Type unidentified so copying all
echo Copy all contents of %fromdir% to %todir%
xcopy %fromdir%\*.* %todir% /S /I /Y
GOTO:EOF

:copyfile
rem Copies single file from fromdir to todir
echo Single file so just copying
echo Copy %filename% from %fromdir% to %todir%
xcopy %fromdir%\%filename% %todir%\ /S /Y
GOTO:EOF

:copymkvs
echo Copy all mkvs from %fromdir% and subdirs to %todir%
xcopy %fromdir%\*.mkv %todir% /S /I /Y
GOTO:EOF

:extractrar
echo Extracts all rars in %fromdir% to %todir%. 
rem Requires WinRar installed to c:\Program files
if not exist %todir% mkdir %todir%
IF EXIST %fromdir%\subs xcopy %fromdir%\subs %todir% /S /I /Y
IF EXIST %fromdir%\subtitles xcopy %fromdir%\subtitles %todir% /S /I /Y
call %winrar% x %fromdir%\*.rar *.* %todir% -IBCK  -ilog"%todir%\RarErrors.log"
IF EXIST %fromdir%\*.nfo xcopy %fromdir%\*.nfo %todir% /S /I /Y
GOTO:EOF
编辑
此外,出于某种原因,第39行没有任何内容打印到日志中。对于那些希望看到带有行号的代码的人:

您说日志没有被写入。将此作为测试进行尝试,看看它是否写入日志

如果它不存在,还有一些其他的基本问题

@echo off
title Liam's torrent-file script
rem Parameter usage: fromdir torrent-name label kind [filename]
rem corresponds to uTorrents flags: %D %N %L %K %F 
echo *********************************************
echo Run on %date% at %time%

set "fromdir=%~1"
set "name=%~2"
set "label=%~3"
set "kind=%~4"
set "filename=%~5"
set "savepartition=F:\Completed Torrents"
set "winrar=C:\Program Files (x86)\WinRAR\WinRAR.exe"
set "torrentlog=F:\Torrent Scripts\logs\torrentlog.txt"
set "handledlog=F:\Torrent Scripts\logs\handled_torrents.txt"
set "errorlog=F:\Torrent Scripts\logs\ErrorLog.txt"
set "label_prefix="

set "handledlog=%userprofile%\desktop\handled_torrents.txt"

>> "%handledlog%" echo Input: "%fromdir%" "%name%" "%label%" "%kind%" "%filename%"
>> "%handledlog%" echo %date% at %time%: Handling "%label%" torrent "%name%"

给你几块:

1) 很可能,您的脚本没有移动文件。首选项/目录有一个选项,可以在下载完成后移动下载。请验证这些设置不会移动文件

2) uTorrent在完成时锁定文件,以便种子设定可以继续。要更改此行为,请转到Preferences/Advanced并将“完成”上的bt.read\u only\u设置为false

3) 你仍然会被挫败,因为“在洪流结束时运行这个程序”并没有真正做到它所说的。当下载量达到100%时,它运行程序,但uTorrent仍在移动文件或进行种子设定。请看我的错误报告

文章的快速摘要,以防文章被删除:您必须在“torrent更改状态时运行此程序:”中设置命令,添加%S参数并检查%S==11


4) 我尝试做一些非常类似的事情,这只是其中的一个提示:当您从参数设置变量时,添加一个波浪号(%~1,而不是%1)。这将去掉引号,让我们以后更容易用变量构建命令行。

代码中有引号问题的行比正确的行多。正如您可能知道的,这是一个“专业和热心程序员”的地方,而不是抄袭者。您似乎有很多
echo
语句显示处理过程中的事件。现在在你和我们分享这些之前,如果你读第一行,“基于另一行”,我们将能够更好地帮助…@endro。我从未承认自己是专业人士,但我喜欢编程。不幸的是,它不是那样工作的。。。一旦torrent完成,它就会运行批处理脚本。不管你在它里面放了多少暂停语句,它都会绕过它们。你甚至看不到窗口。试着缩小你的问题范围,或者把注意力集中在不符合预期的特定行上。如果你的问题有一百行代码,而你只是说“它不工作”,你就不能指望得到一个好答案。例如,有很多方法可以到达:copyfile,但我们无法知道它是如何到达您的案例中的,因此无法知道%todir%的值。试着删除所有不必要的代码,然后编辑你的问题,这样你最多只需要呈现十几行代码。到那时,你很可能已经自己发现了问题。很不幸,这也有同样的结果(那么批处理文件没有运行,或者日志文件有权限问题。请再次尝试上面编辑的代码,查看是否在桌面上创建了日志文件。我知道批处理文件运行,因为它执行脚本的移动部分(只是不到正确的文件夹)。不,它没有运行。除非您测试了上述内容并创建了日志文件。如果它没有创建日志文件,则Utorrent很可能会自行将文件移动到已完成的文件夹中。