René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
gotodir.pl | ||
The directory structure under
T:\somedir is something like:
The script allows to cd into
t:\somedir\2 Bar\22 No Bar\222 Barbarian with a
perl gotodir.pl 222
(On windows, that is...)
use warnings; use strict; my $tmp_file_with_cd_instruction = 'c:\temp\_gotodir.bat'; my $start_dir = 'T:\somedir'; if (@ARGV == 0) { printf("\n\n** No directory specified **\n\n"); exit 0; } my $dir_sought = $ARGV[0]; my $dir_level = 1; printf("Sought Directory is: $dir_sought\n"); my $cur_dir = $start_dir; while ($dir_level <= length($dir_sought)) { my $dir_figures = substr($dir_sought, 0, $dir_level); opendir DIR, $cur_dir or die "Konnte $cur_dir nicht öffnen\n"; my @filenames = readdir DIR; closedir DIR; $cur_dir = $cur_dir . '\\' . (grep /^${dir_figures}_/, @filenames)[0]; $dir_level++; } open T, ">$tmp_file_with_cd_instruction" or die "Konnte $tmp_file_with_cd_instruction nicht öffnen"; print T "\@cd /d $cur_dir\n"; close T; |