shapoval

Make symlinks to all files

May 26th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | None | 0 0
  1. $baseTargetPath = '/var/www/target';
  2.  
  3. $baseSourcePath = '/var/www/sources';
  4. $sources = scandir($baseSourcePath);
  5.  
  6. $counter = 0;
  7. $MAX_COUNT = 1000;
  8.  
  9. foreach ($sources as $filename) {
  10.     $fullSourcePath = $baseSourcePath . '/' . $filename;
  11.     $fullTargetPath = $baseTargetPath . '/' . $filename;
  12.     if (in_array($filename, ['.', '..']) || is_dir($fullSourcePath) || file_exists($fullTargetPath)) {
  13.         continue;
  14.     }
  15.  
  16.     symlink($fullSourcePath, $fullTargetPath);
  17.     $counter++;
  18.  
  19.     if ($counter >= $MAX_COUNT) break;
  20. }
  21.  
  22. var_dump(scandir($baseTargetPath));
Advertisement
Add Comment
Please, Sign In to add comment