1 2 3 4 5 6 7
my $sth = $dbh->prepare( "SELECT name,size,id,pid,mtime FROM $tabelle" ); $sth->execute(); while(my @elm=$sth->fetchrow_array()) { my $line=join(',',map{'"'.$_.'"'}@elm); print $line."\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/perl use strict; use warnings; $| = 1; use File::Find; use File::Spec; use DBI; use DBD::CSV; use Text::CSV; # Verzeichnis von Kommandozeile holen my $verzeichnis = shift(@ARGV) || 'C:\Users\Ordner'; # Array für die gefundenen Dateien my @dateien; my $id = 0; my $parent; my %ids; sub wanted { if ( $_ ne '..' ) { $ids{ $File::Find::name } = $id; $parent = $File::Find::dir; push @dateien,{ id => $id++, fullname => $File::Find::name, name => $_, size => (stat($File::Find::name))[7], parent => $parent, parentid => $ids{ $parent }, stat => [ (stat($File::Find::name))[8,9,10] ] }; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
#!/usr/bin/perl use strict; use warnings; $| = 1; use File::Find; use DBI; # Verzeichnis von Kommandozeile holen my $verzeichnis = shift(@ARGV) || 'C:\Users\Ordner'; my $ausgabe_verzeichnis = shift(@ARGV) || 'C:\CSV_Ordner'; my $cvs_name = "dir.csv" my $id = 0; my $parent; my %ids; my $dbh = DBI->connect ("dbi:CSV:", undef, undef, { f_dir => $ausgabe_verzeichnis, csv_tables => { dir => { file => $cvs_name } }, }); $dbh->do ("DROP TABLE dir"); $dbh->do ("CREATE TABLE dir (fullname CHAR (64), name CHAR (64),size INTEGER,id INTEGER,pid INTEGER,mtime INTEGER)"); my $sth=$dbh->prepare('INSERT INTO dir (fullname,name,size,id,pid,mtime) VALUES(?,?,?,?,?,?)'); sub wanted { return if ( $_ eq '..' ); return if ( $_ eq '.' ); $ids{ $File::Find::name } = $id; $parent = $File::Find::dir; $sth->execute( $File::Find::name, $_, (stat($File::Find::name))[7], $ids{ $parent }, (stat($File::Find::name))[9], ); } } $sth->finish(); $dbh->disconnect();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/perl use strict; use warnings; $| = 1; use File::Find; use Text::CSV; # Verzeichnis von Kommandozeile holen my $verzeichnis = shift(@ARGV) || 'C:\Users\Ordner'; my $csv_name = shift(@ARGV) || 'C:\CSV_Ordner\dir.csv'; my $id = 0; my $parent; my %ids; my $csv=Text::CSV->new(); open(my $cvsfh,'>',$csv_name) or die("ERROR open $csv_name $!\n"); peint $cvsfh "#fullname,name,size,id,pid,mtime\n"; sub wanted { return if ( $_ eq '..' ); return if ( $_ eq '.' ); $ids{ $File::Find::name } = $id; $parent = $File::Find::dir; $csv->print ($cvsfh, [ $File::Find::name, $_, (stat($File::Find::name))[7], $ids{ $parent }, (stat($File::Find::name))[9], ]); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/perl use strict; use warnings; $| = 1; use File::Find; use Text::CSV; # Verzeichnis von Kommandozeile holen my $verzeichnis = shift(@ARGV) || 'C:\Users\Ordner'; my $csv_name = shift(@ARGV) || 'C:\Users\AAA\Desktop\dir.csv'; my $id = 0; my $parent; my %ids; my $csv=Text::CSV->new(); open(my $cvsfh,'>',$csv_name) or die("ERROR open $csv_name $!\n"); print $cvsfh "#fullname,name,size,id,pid,mtime\n"; sub wanted { return if ( $_ eq '..' ); return if ( $_ eq '.' ); $ids{ $File::Find::name } = $id; $parent = $File::Find::dir; $csv->print ($cvsfh, [ $File::Find::name, $_, (stat($File::Find::name))[7], $ids{ $parent }, (stat($File::Find::name))[9], ]); }
1 2 3 4 5 6 7
$csv->print ($cvsfh, [ $File::Find::name, $_, (stat($File::Find::name))[7], $ids{ $parent }, (stat($File::Find::name))[9], ]);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/usr/bin/perl use strict; use warnings; $| = 1; use File::Find; use File::Spec; use Text::CSV; my $verzeichnis = shift(@ARGV) || 'C:\Users\Student\Desktop\Dropbox\Dropbox\AZ Darmstadt'; my $csv_name = shift(@ARGV) || 'C:\Users\Student\Desktop\dir.csv'; my $id = 0; my $parent; my %ids; my $csv=Text::CSV->new( { eol => $/ } ); open(my $cvsfh,'>',$csv_name) or die("ERROR open $csv_name $!\n"); print $cvsfh "#fullname,name,size,id,pid,mtime\n"; find(\&wanted, $verzeichnis); sub wanted { return if ( $_ eq '..' ); return if ( $_ eq '.' ); $ids{ $File::Find::name } = $id; $parent = $File::Find::dir; $csv->print ($cvsfh, [ id => $id++, fullname => $File::Find::name, name => $_, parent => $parent, parentid => $ids{ $parent }, stat => [ (stat($File::Find::name))[8,9,10] ] ; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
#!/usr/bin/perl use strict; use warnings; $| = 1; use File::Find; use File::Spec; use Text::CSV; # Verzeichnis von Kommandozeile holen my $verzeichnis = shift(@ARGV) || 'C:\Users\Student\Desktop\Dropbox\Dropbox\AZ Darmstadt'; my $csv_name = shift(@ARGV) || 'C:\Users\Student\Desktop\dir.csv'; # Array für die gefundenen Dateien my @dateien; my $id = 0; my $parent; my %ids; sub wanted { if ( $_ ne '..' ) { $ids{$File::Find::name} = $id; $parent = $File::Find::dir; push @dateien, { id => $id++, fullname => $File::Find::name, name => $_, parent => $parent, parentid => $ids{$parent}, size => ( stat($File::Find::name) )[7], mtime => ( stat($File::Find::name) )[9] }; } } # Dateien einlesen find( \&wanted, File::Spec->rel2abs($verzeichnis) ); my $csv = Text::CSV->new( { eol => $/ } ); open( my $cvsfh, '>', $csv_name ) or die("ERROR open $csv_name $!\n"); print $cvsfh "#fullname,name,size,id,pid,mtime\n"; for my $datei (@dateien) { $csv->print( $cvsfh, [ $datei->{fullname}, $datei->{name}, $datei->{size}, $datei->{id}, $datei->{parentid}, $datei->{mtime} ] ); } close( $cvsfh ) or die("ERROR close $csv_name $!\n");