0

I have a large number of websites running the same CMS that I want to update as a batch. As the update process just requires copying the updated files into the folder of the given sites, a batch files seems suitable to the task.

Is there a good method for iterating through a list of folders one level deep (don't need to check deeper), checking if a specific file exists in that folder, and if found, run some commands (in this case, I will have it run a command to copy from a destination to the folder)?

Jason C
  • 3
  • 3

2 Answers2

0

What OS are you running on? Something like this would work for Perl:

opendir DIR, $dirname or die "Couldn't open dir '$dirname': $!";
my @files = readdir(DIR); 
closedir DIR; 

foreach my $file (@files) {
   if ($file =~ /filename/) {
      print "Matched file process";
   }
}
slm
  • 7,615
  • 16
  • 56
  • 76
0

In this case, you can use Forfiles command ( It's native in Windows 7/2008/Vista and must install from Resource Kit in Windows Server 2003 ).

Just list all your folder in a text file. Then using a for loop to iteract each folder, feeding them to Forfiles command with /p param, search for specify filename with /m param. If matching, execute command with /c param.

Anyway, I advice you using some more powerfull tools like PowerShell.

cuonglm
  • 2,386
  • 2
  • 16
  • 20
  • That worked. 'forfiles /p "" /s /m /c "cmd /c call "%~f0" /callback @path"' And then used @path – Jason C Jun 25 '13 at 20:30