比特精灵文件移动小助手
使用比特精灵下载BT ,下载完成后 自动移动文件至磁盘其它位置(原来比特精灵有此功能,后来被认为是鸡肋,去除了)做种期间,不移动文件,做种结束后移动,自动生成日志(仅记录成功和失败的任务),可通过手动配置文件来指定”目标文件夹 dir“和“循环检查文件是否被占用的间隔时间 time”(毫秒)
配置文件
dir=f:\
time=122000利用比特精灵的“病毒检查”来完成,如图设置
源码:
#NoTrayIcon
#include <array.au3>
#include <file.au3>
#Include <WinAPI.au3>
$settingfilename = @ScriptDir&"\"&StringTrimRight(@ScriptName, 3) & "ini" ;配置文件名
If Not FileExists($settingfilename) Then IniWriteSection($settingfilename,'setting',"dir=f:\" & @LF & "time=122000" ) ;如果没有配置文件,则自动生成
$logfile=@ScriptDir&"\moved.log" ;日志文件
$destdir=IniRead($settingfilename,"setting",'dir',"f:\") ;读取配置中的目标位置
$time=IniRead($settingfilename,"setting",'time',122*1000);读取配置中的间隔时间
If $cmdline > 0 Then
Sleep($time)
$starttime=@YEAR&'-'&@MON&'-'&@MDAY&' '&@WDAY&' '&@HOUR&':'&@MIN&':'&@MSEC
$ii=0
$files=_FileSearchToArray($CmdLine , "*", 1)
;~ _ArrayDisplay($files)
Do
$a=0
If IsArray($files) Then
For $i=1 To $files
$a+=_IsUseIng($files[$i])
Next
EndIf
;~ If $a=0 Then
;~ MsgBox(0,"no","no")
;~ Else
;~ MsgBox(0,'yes','yes')
;~ EndIf
If $a>0 Then
;~ MsgBox(0,'file using','fileusing',4)
Sleep($time)
ContinueLoop
EndIf
Until $a=0
Do
$ii+=1
$a=DirMove( $CmdLine ,$destdir ,1)
If $ii=3 Then ExitLoop
Until $a=1
$hfile=FileOpen($logfile,1)
If $ii <3 Then
FileWriteLine($hfile,$starttime&'<==>'&@YEAR&'-'&@MON&'-'&@MDAY&' '&@WDAY&' '&@HOUR&':'&@MIN&':'&@MSEC&' '&$CmdLineRaw&' 成功')
Else
FileWriteLine($hfile,$starttime&'<==>'&@YEAR&'-'&@MON&'-'&@MDAY&' '&@WDAY&' '&@HOUR&':'&@MIN&':'&@MSEC&' '&$CmdLineRaw&' 失败' & $i)
EndIf
FileClose($hfile)
EndIf
Func _FileSearchToArray($sPath, $sFilter = "*", $sFalg = 0, $sSub = True)
Local $sfilelist
Local $sOutdir = @ScriptDir
If StringRight($sOutdir,1)<>"\" Then $sOutdir = $sOutdir & "\"
If StringRight($sPath, 1) <> "\" Then $sPath = $sPath & "\"
;-----------修正bug: 使用dir时,如果搜索目录与临时目录有包含,会多出一个临时文件--------------
If $sSub Then
If StringLeft($sOutdir, StringLen($sPath))=$sPath Then
$sOutdir = @TempDir & "\"
If StringLeft($sOutdir, StringLen($sPath))=$sPath Then $sOutdir = @WindowsDir & "\"
EndIf
Else
If $sOutdir = $sPath Then
$sOutdir = @TempDir & "\"
If @TempDir=@ScriptDir Then $sOutdir = @WindowsDir & "\"
EndIf
EndIf
;-----------------------------------------------------------------------------------
Local $sOUT = $sOutdir & "temp_filelist.txt"
Local $bBak=False, $sBakFile=@tempdir&"\temp_$$$$bak.txt"
If FileExists($sOUT) Then ;原文件备份
FileMove($sOUT, $sBakFile, 1)
$bBak=True
EndIf
_FileCreate($sOUT)
If @error Then
$sfilelist = -1
If $bBak Then FileMove($sBakFile, $sOUT, 1)
Return $sfilelist;文件无法创建,$sfilelist = -1,此函数无法应用,因为必须创建临时文件
EndIf
If StringInStr(FileGetAttrib($sPath),"D")<=0 Then
$sfilelist = -2
If $bBak Then FileMove($sBakFile, $sOUT, 1)
Return $sfilelist;无此目录,返回-2,不用浪费时间了
EndIf
If $sSub Then
$sSub = " /s"
Else
$sSub = ""
EndIf
If StringReplace($sFilter," ","") = "" Then $sFilter = "*"
$sFalg = Int($sFalg)
If $sFalg<0 Or $sFalg>2 Then $sFalg=0;规范$sFalg
Select
Case $sFalg = 1;只文件
$sFalg = "/a:-d"
Case $sFalg = 2;只目录
$sFalg = "/a:d"
Case Else
$sFalg = "/a"
EndSelect
RunWait(@ComSpec & ' /c ' & 'dir "' & $sPath & $sFilter & '" ' & $sFalg & ' /b' & $sSub & ' > "' & $sOUT & '"', '', @SW_HIDE)
;Local $t=TimerInit()
_FileReadToArray($sOUT, $sfilelist)
If Not IsArray($sfilelist) Then
Local $sfilelist
$sfilelist = 0
If $bBak Then FileMove($sBakFile, $sOUT, 1)
Return $sfilelist;该目录无文件
Else
If $sfilelist[$sfilelist] = "" Then;最后一行
_ArrayDelete($sfilelist, $sfilelist)
;ReDim $sfilelist[$sfilelist]
$sfilelist = $sfilelist - 1
EndIf
EndIf
;ConsoleWrite(TimerDiff($t)/1000&@CRLF)
Local $x
If $sSub = "" Then
For $x = 1 To $sfilelist
$sfilelist[$x] = $sPath & $sfilelist[$x]
Next
EndIf
FileDelete($sOUT)
If $bBak Then FileMove($sBakFile, $sOUT, 1)
Return $sfilelist
EndFunc ;==>_FilesearchToArray
Func _IsUseIng($hFile)
If Not FileExists($hFile) Then Return False
$hFile = _WinAPI_CreateFile($hFile, 2,6)
If $hFile=0 Then
Return 1
Else
_WinAPI_CloseHandle($hFile)
Return 0
EndIf
EndFunc
;~ a检测文件是否正被使用
;~ 返回值:false=未使用
;~ 返回值:true=使用中
支持你, 想法很好啊, 再接再厉
页:
[1]