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)?

2
  • Batch as in Windows batch? Commented Jun 25, 2013 at 17:55
  • Yes, Windows batch. Commented Jun 25, 2013 at 19:31

2 Answers 2

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.

1
  • That worked. 'forfiles /p "<basepath>" /s /m <file searched> /c "cmd /c call "%~f0" /callback @path"' And then used @path Commented Jun 25, 2013 at 20:30
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"; } } 
1
  • Windows Server 2012 R2 Commented Jun 25, 2013 at 19:32

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.