-
Notifications
You must be signed in to change notification settings - Fork 0
/
double-file-finder.php
55 lines (41 loc) · 1.1 KB
/
double-file-finder.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
<?php
//http://www.if-not-true-then-false.com/2012/php-pdo-sqlite3-example/
try {
$file_db = new PDO('sqlite:files.sqlite3');
$file_db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$file_db->exec(
"CREATE TABLE IF NOT EXISTS files (
file_sha1 TEXT,
file_path TEXT
)"
);
$insert = "INSERT INTO files (file_sha1, file_path) VALUES (:file_sha1, :file_path)";
$stmt = $file_db->prepare( $insert );
$stmt->bindParam( ':file_sha1', $sha1 );
$stmt->bindParam( ':file_path', $path );
$targetPath = realpath( $argv[1] );
$files = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $targetPath ),
RecursiveIteratorIterator::SELF_FIRST
);
$count = 0;
$start = new DateTime();
foreach( $files as $name => $file ){
if( $file->isDir() ) {
continue;
}
$path = $file->getPathname();
$sha1 = sha1_file( $path );
$stmt->execute();
echo "$path\n";
$count++;
}
echo "Scanned files: $count\n";
$end = new DateTime();
$timespan = $end->diff($start);
echo $timespan->format('%H:%i:%s');
$file_db = null;
}
catch( PDOException $e ) {
echo $e->getMessage();
}