develooper Front page | perl.beginners | Postings from March 2002

Directories creating but files are not copying

From:
John Marion
Date:
March 18, 2002 19:45
Subject:
Directories creating but files are not copying
Message ID:
FJENIMPOGBGKJCLBEFIDEEMECAAA.jmarion1@attbi.com
I have been working on this script for a little while and hope that I can
find some fresh eyes to look at it.

I create a list then use the list to create the directories.  Once the
directories are created I would like to recurse the files into the
directories that they are coming from ( this is a cd application install for
a server).  We got the drectories to create then the files would copy to the
basedir (C:\junk\save\, so we thought it was a timing issue so we have moved
the build directory part to another script called by the first one and
niether of them work now.

John

Here are both the files:


#!C:\NTRESKIT\perl
#use File::Copy;
#does C:\ntapps\common\C exist?
#add user notification using Win32::Console

$startdir = "\\ntapps\\common\\c";

@filespec = ('exe', 'dll');

@filedelete = glob ("\\junk\\save\\*.*");

#@cmd = ('dir');

$savedir  = 'C:\junk\save';

#sub searchDirectory;
#sub builddirectory;



if (-e "\\ntapps\\common\\c"){
	#Find all EXE's and DLL's
	open (OUTFILE, '>\ntapps\log\mv_common_c.lst');

	searchDirectory($startdir,"",@filespec);

	#removing files from junk\save
	unlink @filedelete;
	#rename files using the system
	system ("rename" ,'C:\junk\save\*.*', '*.old');

	close (OUTFILE);
	movefiles();

}else

	print "missing \n";
}


# use THIS TO FIND EXE'S AND DLL's
sub searchDirectory {
	# $startdir is a path name, @filespec is a list of file extensions only(ie:
exe, dll, ...)
	local($basedir,$startdir,@filespec) = @_;
	local(@lines);
	local($subdir);
	local($lvl_counter);
	local($list_length);

	#print "got to search directory\n";
	if(opendir (DIR,$basedir.$startdir))
	{
	  @lines = readdir (DIR);
	  closedir (DIR);
	  $lvl_counter = 2;
	  $list_length = ( scalar @lines );
	    while ($lvl_counter < $list_length)
	    {
	      $subdir = $startdir."\\".$lines[$lvl_counter];
	      if(!searchDirectory($basedir,$subdir,@filespec))
	      {
	        processnames($startdir.'|'.$lines[$lvl_counter],@filespec);
	      }
	      $lvl_counter++;
	    }
	}else {
		return 0;
	}
	return 1;

}


sub processnames {
	# Give the value passed to this sub a sensible name.
	my ($filename,@filespec) = @_;

	$match = join '|', @filespec;
	if ($filename =~ /($match)$/i) {
		print (OUTFILE "$filename\n");

	}
}


sub movefiles {
	local ($name, $path, $filename, $topath);
	#This is moving the files on the list we created to junk\save
	#open input file
		print "inputlist\n";
	open (INPUTLIST, '<\ntapps\log\mv_common_c.lst');
	foreach $file (<INPUTLIST>) {
		($path,$name) = split (/\|/, $file);
		if (!-e  $savedir.$path."\\" && !$path == "" ) {
			$topath = $savedir.$path;
			print "path:$path\n";
			print "making directory: $topath\n";
			#mkdir ($topath, 0777) || die "cannot mkdir $topath: $!";
			`C:\\john\\ldapps\\perl\\buildir.pl $savedir, $path`;
			opendir dumb, $topath;
			closedir dumb;
		}
		if (!-d $basedir ) {print "ouch\n" }
		$command = 'copy '.$startdir.$path."\\".$name.' C:\junk\save'.$path;
		print "$command\n";
		print "path:$topath, name:$filename\n";
		system ($command);
		last;

	}
	close (INPUTLIST);
}



#this assumes that basedir exists
sub builddirectory {


}


#second script buildir.pl

#!C:\NTRESKIT\perl

local ($basedir, @path) = @_;
	local ($directory);

	@sublist =  ($#path <1) ? (split(/\\/, $path[0])) : (@path) ;
	print "$#path, $#sublist, @path, @sublist\n";
	foreach $directory (@sublist) {
	  if ($directory =~ /\s/) { next; }
	  if (!-e $basedir.'\\' .$directory) { mkdir($basedir. '\\' .$directory,
0777); }
	  $basedir .= '\\'.$directory;
	  print "$basedir\n";

	}





nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About