PDA

View Full Version : .bat file



SolMiester
26-03-2010, 04:30 PM
Hey, calling batch file gurus....

I need to copy a file to all users personal directory from the root above and overwrite existing...

can anyone help?

ta

Erayd
26-03-2010, 05:14 PM
#!/bin/sh
STARTDIR="/home/users"
FILENAME="copyme.txt"
cd "$STARTDIR"
ls | while read f; do
if [ -d "$f" ]; then
cp -f "$FILENAME" "$f/$FILENAME" || echo "Failed to copy into $f" >&2;
fi
done

fred_fish
26-03-2010, 05:51 PM
for /f %%a in ('dir /b /a:d') do copy /y textfile.txt "%%a"

If you want to run it as a command instead of in a batch file, just use 1 x % sign.

Erayd
26-03-2010, 07:03 PM
Oops - ignore my previous post - it's a posix shell script, and won't run on Windows. My bad.