<?xml version="1.0" encoding="windows-1252"?>
<node id="783254" title="File Backup Utility" created="2009-07-25 23:04:27" updated="2009-07-25 23:04:27">
<type id="1748">
sourcecode</type>
<author id="779255">
misterMatt</author>
<data>
<field name="doctext">
&lt;code&gt;
=head1 NAME

File autobackup utility

=head1 SYNOPSIS

  autobackup -d:
  		The d flag backs up files to/from the locations hardcoded into 
  		the script. Only use this if you have edited in your own locations.  		
  autobackup -h:
  		The h flag displays usage information. Use it for instructions.
  
  autobackup -p FILEPATH:
  		The p flag should be used if you have not set up the script to work with the d flag. 
  		When calling the script with the p flag, you should specifiy the filepath of the files you want 
  		to be copied as an argument: "autobackup -p C:\myfiles". You will then be asked for a target 
  		location for the files in the directory that you specified when you called the program. 
  		
  I'M ASSUMING WE ALL KNOW HOW TO ENTER PROPPER FILEPATHS... 

=head1 DESCRIPTION

In a nutshell, this script copies files from one location to another. 
I wrote this script to transfer files from my computer to an external drive easily more easily.

=head1 DEPENDENCIES

This script requires the File::Copy::Recursive module. 

=head1 AUTHOR

Matthew Young (mabufo@gmail.com) [www.theangrywalrus.com/blog]

=cut


#!usr/bin/perl
use strict;
use warnings;
use File::Copy::Recursive qw(dircopy);
use Getopt::Std;
use Pod::Usage;

#--------file copy vars (uncomment if you want)
#local $File::Copy::Recursive::SkipFlop = 1; #keeps the script going if somethign fails
#$File::Copy::Recursive::MaxDepth #you can set this to change the maximum depth of the copy.

#I get to play with hashes a bit...
#grabs our argv values and stores them in a hash (key is the flag, value is the actual argument)
my %options=();

getopts('dp:h', \%options); 
pod2usage(2) if (keys %options != 1);

if ($options{d}){
	#if 'default' flag: 
	#paths can be changed by editing what's in qw() - on the left is location of files, 
	#on the right is where you want to put them.
	my ($original, $targetlocation) = qw/C:\test C:\test1/;
    my ($numberoffiles, $numberofdirs, $depth) = dircopy($original, $targetlocation) or die $!;
	print "$numberoffiles files copied, across $numberofdirs directories, at a level of depth of $depth.";
}
if ($options{p}){
	#if 'path' flag:
	my $original = $options{p};
	print "Target directory: ";
	my $targetlocation = &lt;STDIN&gt;;
	chomp $targetlocation;
	my ($numberoffiles, $numberofdirs, $depth) = dircopy($original, $targetlocation) or die $!;
	print "$numberoffiles files copied, across $numberofdirs directories, at a level of depth of $depth.";
}
if ($options{h}){
	pod2usage(2); #YES!
}





&lt;/code&gt;

Once again I apologize for the formatting - it looks a lot better inside of eclipse :). This is my first actual script - so if you guys see any glaring errors or bad practices - point them out!

EDIT: Now with Pod::Usage!!</field>
<field name="codedescription">
&lt;p&gt;I wrote this utility to assist me in backing up files from my hard drive to an external drive. This is my first perl script! &lt;/p&gt;

&lt;p&gt;I tested this on the latest activeperl installation on windows vista. This script requires File::Copy::Recursive.&lt;/p&gt;

&lt;p&gt;If anyone has suggestions on how to improve this script either by code improvements, or feature additions post your ideas here! I would appreciate it. Sorry about the formatting.&lt;/p&gt; </field>
<field name="codecategory">
Utility Scripts</field>
<field name="codeauthor">
Matthew Young
mabufo@gmail.com</field>
</data>
</node>
