I’m trying to convert a series of bash scripts to batch files. I’m having the following issue with one part of a script, the part performs the following:
Connect to network share, for each folder with a certain root name find the latest version, copy the .zip inside to a local location. It should loop this method through all folders found in a directory, here is the bash version of this:
for f in /xxx/xxx/xxx.xxx.game_android*
do
cd $f
ls | sed 's/_//g' | sed 's/test.sh//g' | sed 's/plist.txt//g' | sed 's/^...//' > $dir/res/temp_list.txt
sort $dir/res/temp_list.txt > $dir/res/temp_list_sorted.txt
rm $dir/res/temp_list.txt
export atom=`tail -n1 $dir/res/temp_list_sorted.txt`
export final=`ls | grep "$atom"`
rm $dir/res/temp_list_sorted.txt
cd $final
echo "Copying atom: $atom"
cp *.zip $dir/res/sb5-games/
echo "Copying File: $f"
done
This works well, but when trying to convert it to batch I’m faced with lots of issues. I was able to install GnuWin32 CoreUtils, Sed, and Grep so I’m able to use all the same tools, but the actual process of looping through all folders in a directory isn’t working.
My question: what format of the FOR command would I use to loop through all folders in a directory with a wildcard, then how would I execute the series of commands I need to on each folder?
Thanks.
You can loop over all folders in
WhateverDirectoryusing the following construct in your batch file:A good batch guide is http://www.ss64.com/nt/ or checkout What is a good windows batch scripting reference guide?