Monthly Archives: September 2009


>igår köpte jag en programvara som skulle hjälpa mig att laga id3-taggar. laddade hem testversionen innan och var jättenöjd. därav köpet.

lycklig började jag mosa in alla mp3 jag äger i itunes och nu är jag inte lika nöjd längre.
hur tänker tuneup egentligen? antingen har man få mp3 och då kan man tagga dom själv. eller har man många mp3 och behöver hjälp.
just nu har jag bara lyckats kopiera in 17000 av c:a 50000 mp3 i itunes och allt är fucked up. tuneup orkar inte.

jag ska aldrig betala för mjukvara igen.

write simple for loops in cmd.exe

sometimes when i need to run a command on multiple computers or folders i use a for loop on the command line.

example 1 – copy a directory to a subfolder in all users home directories

in bash (and probably in all unix shell environments) you can substitute a directory with a wildcard to specify how deep you want to perform a command. for instance, to copy a folder called “templates” to a subfolder called “office” to all users i can do something like this in bash:

cp -R templates /home/*/office/

but in the windows command prompt you can’t. i bet there are a thousand other ways to do it but one i came up with that works like a charm looks like this:

for /d %d in (X:\USERS\*.*) do robocopy "Templates" /l /e /log+:mytemplatescopy.log "%d\office"

who needs vbscript or powershell, right? 🙂

example 2 – how to run a command on a list of computers

i love psexec from sysinternals. if you are not familiar with the tool it is written by Mark Russinovich back when he worked at sysinternals (he is now at microsoft). psexec lets you run commands on remote computers you have administrative permissions on. the tool copies itself to the admin$ share, starts up as a service and runs your command remotely. it also spits out its output to stdout on your cmd prompt.

lets say you have a list of computers that you want to run a script or a program on in a textfile. here is how you do it the for-loop way.

for /f %i in (computers.txt) do psexec \\%i ipconfig

computers.txt is the textfile with one computername on each line. replace ipconfig with your command of choice.