Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: how to copy source folder excluding specific set of sub folder from parent folder

by robby_dobby (Hermit)
on Aug 09, 2016 at 07:57 UTC ( [id://1169389]=note: print w/replies, xml ) Need Help??


in reply to how to copy source folder excluding specific set of sub folder from parent folder

Hello mrityunjaynath,

This is an SVN folder, right? If so, why not just use svn export $srcFolder $targetFolder. I may be wrong on the exact incantation to send to svn export but you get the idea - it'd strip out all .svn folders, exporting only the content at that revision.

HTH. You may not really need perl for this, unless you plan to do it as an exercise. :-)

EDIT:

Here's a link to svn export from svn redbook.

Replies are listed 'Best First'.
Re^2: how to copy source folder excluding specific set of sub folder from parent folder
by mrityunjaynath (Acolyte) on Aug 11, 2016 at 07:20 UTC

    hi robby_dobby.... in continuation to the above querry i have written a code to copy a directory and delete .svn file in particular from the copy directory. havnt used file::Rsync option but written a subroutine to do so but its doing nothing and stucked in infinite loop. the directory is copied but after that when i called subrouting it was stuck in infinite loop showing - only ...the code is

    use strict; use warnings; use File::Copy; use File::Basename; use Cwd; use File::Copy::Recursive qw(dircopy) ; ############################################################ sub traversedir { my $givendir = $_[0]; opendir(my $findsvn , $givendir) or die "Couldn't read dir: $! \n +"; my @traversedfiles = readdir($findsvn); foreach my $searchfile (@traversedfiles) { $searchfile =~ /^\.svn$/; print "$searchfile\n"; rmdir $searchfile; if ( -d $searchfile) { &traversedir($searchfile); } else { last; } } } ############################################################ my $fullpath = cwd(); my $value = 0; my $file = basename($fullpath); my $dir = dirname($fullpath); print("\nWORK DIRECTORY PATH IS $dir \n"); opendir(my $pathindex, $dir ) or die "Couldn't read index : $!\n"; while (my $currentfile = readdir($pathindex)) { print "\nCurrent Directory File $value\t"; print "$currentfile","\n"; $value++; } print "\nENTER THE PROJECT NAME FROM ABOVE LIST\n\n"; my $projectdir = <STDIN>; chop($projectdir); my $projectdirpath = "/"."$projectdir"; my $workingdirectory = ($dir.$projectdirpath); chdir($workingdirectory."/trunk"); my $newpath = cwd(); my $topprojectdir = $newpath; my $source_dirrtl; my $target_dirrtl ; opendir(my $index, $newpath ) or die "Couldn't read index : $!\n"; while (my $file = readdir($index)) { if ($file eq "rtl" ) { if(chdir($newpath."/rtl")) { my $currentworkingdir = cwd(); $source_dirrtl = $currentworkingdir; $target_dirrtl = ("$newpath"."/rtl2"); } last; } elsif ($file eq "vhdl") { if(chdir($newpath."/vhdl")) { my $currentworkingdir = cwd(); $source_dirrtl = $currentworkingdir; $target_dirrtl = ("$newpath"."/vhdl2"); } last; } } closedir($index); my $source_dirsim = ("$newpath"."/sim"); my $target_dirsim1 = ("$newpath"."/sim2"); my $source_dirsynth; my $target_dirsynth1 ; opendir(my $indexs, $newpath ) or die "Couldn't read indexs : $!\n"; while (my $file = readdir($indexs)) { if ($file eq "par" ) { if(chdir($newpath."/par")) { my $currentworkingdir = cwd(); $source_dirsynth = $currentworkingdir; $target_dirsynth1 = ("$newpath"."/par2"); } last; } elsif ($file eq "synth") { if(chdir($newpath."/synth")) { my $currentworkingdir = cwd(); $source_dirsynth = $currentworkingdir; $target_dirsynth1 = ("$newpath"."/synth2"); } last; } } closedir($indexs); mkdir($target_dirrtl,0777); mkdir($target_dirsim1,0777); mkdir($target_dirsynth1,0777); my $filertl = dircopy($source_dirrtl, $target_dirrtl); my $filesim = dircopy($source_dirsim, $target_dirsim1); my $filesynth = dircopy($source_dirsynth, $target_dirsynth1); &traversedir($target_dirrtl);
    please suggest

      After
      sub traversedir { my $givendir = $_[0];
      insert
      print "traversedir $givendir\n";
      Probably you are stumbling over "." and ".." …
      Hi,

      soonix already pointed out the issue around . and .. directory traversals. You'll need to keep track of visited directories to avoid looping over them again. There's also one more path that you can look into:

      $searchfile =~ /^\.svn$/; print "$searchfile\n"; rmdir $searchfile; if ( -d $searchfile) { &traversedir($searchfile); } else { last; }

      Now, this is not necessarily a problem - but you are not really checking for .svn folders, merely matching and overwriting the $searchfile variable. What do you think would happen if there were no match? :-)

      That said, what's wrong with just doing svn export $srcFolder $targetFolder? It doesn't look like you're doing it as an exercise (those vhdl, rtl, sim folders?) If you have svn installed, you already have this tool at your disposal. Why reinvent the wheel? :-)

        But he would have to be concerned about "ignored" files, wouldn't he?
Re^2: how to copy source folder excluding specific set of sub folder from parent folder
by mrityunjaynath (Acolyte) on Aug 09, 2016 at 08:44 UTC

    thanks robby_dobby for replying....yes i am trying to copy svn folders from my local directory to a target directory to do some experiment on target directory...... will try your suggestion and will reply u soon

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-25 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found