--- Peter Lemus <[EMAIL PROTECTED]> wrote:
> HI Folks,
>
> I need to delete some directories, specified in
> removedir.txt, I'll like to check whether the file
> exists or not, if it doesn't I need to print file has
> been deleted. this is what I've done so far.
>
> use file::spec;
> use win32;
> chdir ("c://admin");
> open (FILE1, 'c://admin//remove.txt') || die "can't
> open file he: $!\n";
> sleep 2;
Sleep? Why?
> while (<FILE1>) { # read file line by line.
> my ($user) = split /,/; #assign line output of file to line.
> chdir ('c://admin//test');
> chomp $user;
If $user is loaded from a file with commas, and you're loading it with
split after an implicit read with <FILE1>, then the only way it could
have a newline is if there were no comma on that record. If that's just
data scrubbing, fine... but might you be doing more than necessary?
What's the file format?
> rmdir "/s /\q $user";
"/s /\q $user"?
Perhaps I'm mistaken, but I don't think this is at all what you want.
Perl's rmdir isn't the OS's rmdir.
just rmdir $user is probably all you need there....
> # system ('rmdir /s /q $user');
> #system ('rmdir /s /q $user'); # remove directory
> # if (-d ) { # check if file exist: "please help me here"
you need to tell it what it's checking for.
try this(assuming data scrubbing):
while (<FILE1>) { # read file line by line.
my ($user) = split /,/; #assign line output of file to line.
chdir ('c://admin//test');
chomp $user;
if (-e $user and -d _) {
rmdir $user ? print "Directory $user deleted\n"
: warn "Directory $user NOT removed: $!\n";
}
> }
> print "Specified directory has been deleted \n";
> sleep 2;
Again, why the sleep???
> close FILE1
> EOF
EOF?
> =====
> Peter Lemus
> Computer Networks Engineer
> [EMAIL PROTECTED]
> My Dad always tought me; when you do good; expect to receive good;
> when you do bad; expect the bad...sooner or later.
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Auctions - buy the things you want at great prices
> http://auctions.yahoo.com/
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/