• Win32 Perl

    Actually did my first win32 perl script at work today. What a pita that can be when you are changing from *n?x perl. Most of the problems I encountered were editor issues. Guess I should have just gotten vi for Windows and been done with it.

    ###
    # First we’ll change into the directory passed in the command line
    ###
    $workdirectory = @ARGV[0];
    #print (“$workdirectory\n”);
    chdir (“$workdirectory”) || die “cannot cd to $workdirectory”;

    ###
    # Lets get a numeric date for use in naming the zip files
    ###
    $insanedate = `date /t`;
    # print $insanedate;
    $insanedate =~ /.*?(\d{2})\/(\d{2})\/(\d{4})/;
    $sanedate = “$1$2$3″;
    # print “$sanedate\n”;

    ###
    # Time to backup the .bak files
    ###
    # must include the extension in the form of *.ext
    @baklist = `dir /b *.bak`;
    if (!@baklist)
    {
    # Drop out of the script if there is nothing to backup!
    print “No files to backup”;
    die;
    }
    else
    {
    # This will create a zipfile with the current date.zip
    `pkzip $sanedate.zip *.bak`;

    ###
    # Take care of directory cleanup
    ###
    @filelist = `dir /b /o:d *.zip`;
    # The $keeperN files are the ones that will be (newest) saved,
    # anything left in the list will be removed from the directory
    if (@filelist)
    {
    $keeper1 = pop (@filelist);
    $keeper2 = pop (@filelist);
    # $keeper3 = pop (@filelist);
    # print (“$keeper1″);
    # print (“$keeper2″);
    # print (“$keeper3″);

    # DANGER Will Robinson!! DANGER!!
    `del *.bak`;
    # Activating the following del statement has the potential to
    # do lots of damage. Please check working directory first!
    foreach $leftover (@filelist)
    {
    print $leftover;
    # `del $leftover`;
    }
    }
    else
    {
    print “No zip files, CAUTION!”;
    die;
    }
    }


     Leave a reply




    *