package Win32::Daemon::Go2; use Win32::Daemon::Simple; @ISA = qw(Win32::Daemon::Simple); use strict; use warnings; use File::stat; my $datafile = 'e:\\Commands\\go2.dat'; my $outfile = 'e:\\Commands\\go2.bat'; sub body { my $self = shift; return unless (-e $datafile); $self->{last_mod} ||= 0; my $sb = stat($datafile); if ($self->{last_mod} != $sb->mtime) { $self->{last_mod} = $sb->mtime; my %batch; open(INPUT, $datafile); while (my $target = ) { chomp($target); my ($label, $dest) = split('~', $target, 2); $label =~ s/\s/_/g; $dest =~ s{/}{\\}g; my ($drive, @path) = split(/\\/, $dest); $batch{$label} = { drive => lc $drive, path => \@path, } }; open(OUTPUT, ">$outfile") or croak $@; local $\ = "\n"; print OUTPUT '@echo off'; print OUTPUT 'if "" == "%1" ('; print OUTPUT "\techo \t$_" for sort(grep !/^!/, keys(%batch)); print OUTPUT "\tgoto EOF"; print OUTPUT ')'; for my $label (reverse sort keys(%batch)) { if ($label =~ /^!/) { print OUTPUT join('', 'if "', $label, '" == "%1" ('); print OUTPUT "\tpushd ", join('\\', $batch{$label}{drive}, @{$batch{$label}{path}}, '%2'); print OUTPUT "\tcmd /k"; print OUTPUT "\tpopd"; print OUTPUT "\tcls"; print OUTPUT "\tgoto EOF"; print OUTPUT ')'; } else { print OUTPUT join('', 'if "', $label, '" == "%1" ('); print OUTPUT "\t", $batch{$label}{drive}; print OUTPUT "\tcd \\", join('\\', @{$batch{$label}{path}}, '%2'); print OUTPUT "\tgoto EOF"; print OUTPUT ')'; }; }; print OUTPUT 'echo Destination not found: %*'; print OUTPUT 'echo Try editing E:\command\go2.dat'; print OUTPUT ':EOF'; close(OUTPUT); } } 1;