【问题标题】:Background Script to Check File Transfer检查文件传输的后台脚本
【发布时间】:2015-08-27 06:07:10
【问题描述】:

我必须编写一个脚本来检查后台批处理正在进行的文件传输的进度。我知道文件夹需要具有“完整”状态的文件数。我正在后台 PHP 中尝试以下操作:

$id = $_GET['id'];
$qtd = $_GET['qtd'];

checkProgress($id, $qtd);

function checkProgress($qtd, $id) {
    $dirWav = "D:\\path\\to\\wav\\".$id."\\";
    $dirMP3 = "D:\\path\\to\\mp3\\".$id."\\";

    $progWav = array_diff( scandir($dirWav), array(".", "..") );
    $progMP3 = array_diff( scandir($dirMP3), array(".", "..") );

    $numWav = count($progWav);
    $numMP3 = count($progMP3);

    if ($numMP3 < $qtd OR $numWav < $qtd) {
        sleep(5);
        checkProgress($qtd, $id); //Here i'm trying to do it in a recursive way
    } else {
        //End script, record to the DB
    }
}

我确定被检查的文件夹在启动时是空的,并且批处理运行正常。但是在脚本开始的时候,它会自动走到最后(我用一个 mkdir 偷偷的检查了一下)。

我怎样才能实现我想要的?我无法通过 cronjob 或类似的方式检查它。

【问题讨论】:

    标签: php batch-file background-process file-transfer


    【解决方案1】:

    这是 Powershell,但我猜整个功能将适用于批处理文件。将输入作为两个路径,运行 FOR 循环来计算文件并进行比较。请参阅 here 了解 FOR 循环中的文件计数。

    Function Count-Folders{
    Param
     (
      [parameter(Mandatory=$true,Position=1)][string]$source,
      [parameter(Mandatory=$true,Position=2)][string]$dest
    )
    
    $path = @(gci -Path $source -dir)
    $path2 = @(gci -Path $dest -dir)
    
    If($path.Length -eq $path2.Length){
     "Matches"
    } Else{
    "input folder counts do not match, check again!!!"
    }
    

    【讨论】:

    • 感谢您的支持。我马上试试。
    猜你喜欢
    • 1970-01-01
    • 2020-05-01
    • 2021-11-21
    • 1970-01-01
    • 2014-05-05
    • 2012-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多