-
Notifications
You must be signed in to change notification settings - Fork 975
/
Copy pathmoveFilesToFolder2.php
56 lines (46 loc) · 1.74 KB
/
moveFilesToFolder2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
//streamer config
require_once '../videos/configuration.php';
if (!isCommandLineInterface()) {
return die('Command Line only');
}
set_time_limit(300);
ini_set('max_execution_time', 300);
$global['rowCount'] = $global['limitForUnlimitedVideos'] = 999999;
$path = getVideosDir();
$logFile = $global['logfile'];
echo "Open $logFile" . PHP_EOL;
$handle = fopen($logFile, "r");
$pattern = '/Video::updateDirectoryFilename video folder renamed from \[olddir=(.+)\] \[newdir=(.+)\]/';
if ($handle) {
while (($line = fgets($handle)) !== false) {
if (preg_match($pattern, $line, $matches)) {
//var_dump($matches);
if (!is_dir($matches[2])) {
continue;
}
$glob = glob("{$matches[1]}*");
$totalItems = count($glob);
echo "Found total of {$totalItems} items " . PHP_EOL;
$countItems = 0;
foreach ($glob as $file) {
if (is_dir($file)) {
continue;
}
$pathInfo = pathinfo($file);
$sourceFilename = Video::getCleanFilenameFromFile($file);
$filename = Video::getCleanFilenameFromFile($matches[2]);
$basename = str_replace($sourceFilename, $filename, $pathInfo['basename']);
$destinationFile = "{$matches[2]}{$basename}";
//var_dump($pathInfo, $basename,$filename, $sourceFilename, $destinationFile);
$countItems++;
echo "[$countItems/$totalItems] move file {$file} to {$destinationFile}" . PHP_EOL;
rename($file, $destinationFile);
}
}
// process the line read.
}
fclose($handle);
} else {
// error opening the file.
}