Batch Scripts from the Command Line
Comments available as RSS 2.0
I always thought batch scripts were only really useful in linux. I didn't realise windows supported the FOR command. This quick tutorial from Daily Cup of Tech shows you how to recursively search all subdirectories for a particular type of file, then perform an action on every file found.
<strong>for /R %1 in (*.zip) do unzip "%1"</strong> for - indicates that we are going to be using the for command /R - recursively searches all sub-directories within the active directory. %1 - the variable that will contain the filename that is found. This can be any number but it is case sensitive. If you want to use the for command in a batch file, you will need to use %% (e.g. %%z) instead of just %. in (*.zip) - the search pattern that will be found. The portion in parenthesis uses the same wildcard scheme as the dir command. do - indicates that the string following is the command that should be executed on each file found unzip “%1” - the command that is executed for each file. The %1 portion is replaced by the name of the file found. So, for example, if the file found was archive.zip, the command that would be executed would be unzip "archive.zip".







Comments
Leave a Comment