Skip to content

Instantly share code, notes, and snippets.

@colinyoung
Created January 10, 2011 06:10
Show Gist options
  • Save colinyoung/772446 to your computer and use it in GitHub Desktop.
Save colinyoung/772446 to your computer and use it in GitHub Desktop.
#!/usr/bin/php
<?php
$u = "Colin";
$StartsWith = array("@");
$SpecificFiles = array(
"saga.psd"
);
define("FILENAME_START", 51);
/* NO EDITING BELOW THIS LINE */
array_push($SpecificFiles, "Clean Desktop.command");
array_push($SpecificFiles, "Archive");
array_push($SpecificFiles, "Current Projects");
array_push($SpecificFiles, "Archived Projects");
// Create Directory if necessary
$desktop_archive = "/Users/$u/Desktop/Archive";
if (file_exists($desktop_archive)) {
if (!is_dir($desktop_archive))
mkdir($desktop_archive);
} else {
mkdir($desktop_archive);
}
// Count items on desktop
$output = shell_exec('cd ~/Desktop; ls -l');
$line_array = preg_split( '/\n/', $output );
$num_lines = count( $line_array );
for ($i = 0; $i < $num_lines; $i++) {
$flag = false;
$filename = substr($line_array[$i], FILENAME_START);
$filename = trim($filename);
$filename_with_slashes = str_replace(" ", "\ ", $filename);
$filename_with_slashes = str_replace("(", "\(", $filename_with_slashes);
$filename_with_slashes = str_replace(")", "\)", $filename_with_slashes);
if ($i == 0 || $i == 1)
$flag = true;
if ($i == ($num_lines - 1) )
$flag = true;
//if (substr($line_array[$i], 0, 1) == 'd')
// $flag = true;
if (array_search(substr($line_array[$i], FILENAME_START, 1), $StartsWith) !== FALSE)
$flag = true;
if (array_search( $filename, $SpecificFiles) !== FALSE)
$flag = true;
if (!$flag) {
shell_exec("mv /Users/$u/Desktop/$filename_with_slashes $desktop_archive");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment