0

I have to write a script that checks the progress of a file transfer that a background batch is doing. I know the number of files that the folder need to have to have the "complete" status. I'm trying the following in a background 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
    }
}

I'm sure that the folder beign checked are empty on start, and that the batch is running flawless. But at the start of the script, it automatically goes to the end (I used a mkdir to check it in a lazy way).

How can I achieve what I want? I cannot check it via cronjob or something like that.

Metal Sonic
  • 61
  • 1
  • 8

1 Answers1

0

This is Powershell but I'd guess the overall function would apply to a batch file. Take input as two paths, run a FOR loop to count the files and compare. See here for counting files in a FOR loop.

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!!!"
}
Community
  • 1
  • 1
user4317867
  • 2,397
  • 4
  • 31
  • 57