Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Deleting Directories from a path by reading information from Database columns

by tokpela (Chaplain)
on Dec 28, 2010 at 23:23 UTC ( #879531=note: print w/ replies, xml ) Need Help??


in reply to Deleting Directories from a path by reading information from Database columns

Are you looking for a way to delete the directories using the Id directory using the "number" column and base directory (c:\Documents and Settings\user\Files)?

If so, then check out remove_tree in the File::Path module.

remove_tree( $dir1, $dir2, ...., \%opts )

The remove_tree function deletes the given directories and any files and subdirectories they might contain, much like the Unix command rm -r or del /s on Windows.

use strict; use warnings; use DBI; use File::Path; my $base_directory = 'c:/Documents and Settings/user/Files'; my $db = DBI->connect( "dbi:Oracle:*****", "*****", "*** +***" ) || die( $DBI::errstr . "\n" ); $db->{AutoCommit} = 0; $db->{RaiseError} = 1; $db->{ora_check_sql} = 0; $db->{RowCacheSize} = 16; my $SEL = "SELECT number,id,status FROM info where statu +s in ('I,D')"; my $sth = $db->prepare($SEL); $sth->execute(); while ( my $row = $sth->fetchrow_hashref() ) { my $folder = $row->{number}; # folder my $subfolder = $row->{Id}; # subfolder my $directory = "$base_directory/$folder/$subfolder"; if (-d $directory) { if (remove_tree($directory)) { print "DIRECTORY HAS BEEN DELETED:: [$directory]\n"; } else { print "[Error] UNABLE TO DELETE DIRECTORY: [$directory]\n"; } } } ...


Comment on Re: Deleting Directories from a path by reading information from Database columns
Download Code
Re^2: Deleting Directories from a path by reading information from Database columns
by Anonymous Monk on Dec 29, 2010 at 00:01 UTC

    Hi, I tried your code and it is showing the following errors:
    Use of uninitialized value in concatenation (.) or string at ./db0.pl line 29.

    Use of uninitialized value in concatenation (.) or string at ./db0.pl line 29.

    Undefined subroutine &main::remove_tree called at ./db0.pl line 35.

    line 29 is : my $directory = "$base_directory/$folder/$subfolder";

      You need to import remove_tree, as I said in an earlier post.

      And can you please do the most rudimentary of debugging to see what is undefined? Obviously your data doesn't look like you think it does.

        Hi, Based on the script above all the values are initialized. So not sure why these errors are coming up and I changed remove_tree to rmtree.

        so it is going to the $basedirectory location and deleting the whole thing

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://879531]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-09-21 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls