Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

problem going through sub directories

by splitOnce (Acolyte)
on Aug 29, 2002 at 19:18 UTC ( [id://193868]=perlquestion: print w/replies, xml ) Need Help??

splitOnce has asked for the wisdom of the Perl Monks concerning the following question:

Hello there , I have the following code:
my @todo = glob('d:/Profiles/sal/Desktop/testFolder/*.bld'); # some k +ind of file my %done; undef $/; while(@todo) { my $file = shift @todo; print "File Name : $file\n"; open FILE, "+<$file" or die "Can't open file $file: $!"; $_ = <FILE>; # whole contents of file if(s/\bold\b/new/g) { # replace contents of file seek FILE, 0, 0; truncate FILE, 0; print FILE; } my($dir) = $file =~ m[(.*/)]; while(/^#include (\S+);/mg) { push @todo, "$dir$1" unless $done{"$dir$1"}++; } }
where I am trying to get all the .bld file and change the word old to new within each .bld file,, the problem I am facing is that the .bld file contains sub .bld's which I need to change as well
-hi.bld -do.bld +one.bld
with the code above I was able to get the hi.bld wich is the top level file to change however the subfiles like do.bld and one.bld don't get affacted ,, I was thinking maybe because hi.bld is not a directory but contains sunfiles under it .. I am kinda of lost ,, do you see the problem I am missing .. thanks

Replies are listed 'Best First'.
Re: problem going through sub directories
by bart (Canon) on Aug 29, 2002 at 20:29 UTC
    Hmm... I think I recognize some of that code... Oh yeah, I wrote it. It looks like this is a continuing quest... (Have you changed username?)

    OK, I think your main problem is that the directory you try for your include files, isn't the proper one. Just print out the paths for the file you're trying to access.

    Er... your code does print out the file paths. Don't you see anything wrong with what is printed?

Re: subDIR problem
by RollyGuy (Chaplain) on Aug 29, 2002 at 19:19 UTC
    You mention that you have sub-files that are called by higher-level files. Are these sub-files in the same directory? If they are in a sub-directory to d:/Profiles/sal/Desktop/testFolder/, then the globbing won't pick them up.

    You probably want to look into File::Find to traverse the directories and act on each blk file.

    Good luck.
    -Rolly
      somthing like that :
      d:/Profiles/sal/Desktop/testFolder/hi.bld/low.bld
        ???

        If d:/Profiles/sal/Desktop/testFolder/hi.bld/low.bld is a file, how can d:/Profiles/sal/Desktop/testFolder/hi.bld/low.bld also exist? A file can't be both a file and a directory, you know.

        Perhaps you ment to drop the parent file's extension, as in d:/Profiles/sal/Desktop/testFolder/hi/low.bld

Re: problem going through sub directories
by Django (Pilgrim) on Aug 29, 2002 at 19:24 UTC

    I'd suggest to use File::Find;

    ~Django

    "Why don't we ever challenge the spherical earth theory?"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://193868]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found