can anyone provide or show me how to write a .cmd file that will copy a file to the same folder for every profile on a Windows 7 machine? So if I have 3 profiles or 30 it will still copy the file to every folder.
0 Comments   [ - ] Hide Comments


Please log in to comment

Answer this question or Comment on this question for clarity


What if you looped through everything in:
dir /b %userprofile%\..
Answered 03/26/2012 by: dchristian
Red Belt

  • I tried that and I guess I wrote in wrong. I have this: for /f %%a in ('dir /b "%userprofile%") do start copy *.txt %userprofile% %%a and it says it can't find file /b myProfile
    • There's two dot's (..) at the end of the %userprofile%.
      This tells the command to go up a level, so you can get the listing.
Please log in to comment
I tried that and it gives me this error output.

C:\Temp>for /F %a in ('dir /b "") do start copy *.txt C:\Users\MyUserProfile %a
The system cannot find the file 'dir /b "".

Press any key to continue . . .
Answered 03/27/2012 by: mhsl808
Fifth Degree Brown Belt

  • Here's a simplified example.

    @echo off
    set filer=C:\myfile.txt
    IF NOT EXIST %filer% (
    IF EXIST C:\users (
    for /f %%a in ('dir /b "C:\users\"') do xcopy /Y %filer% "c:\users\%%a\"

    IF NOT EXIST C:\users (
    for /f %%b in ('dir /b "c:\Documents and Settings\"') do xcopy /Y %filer% "c:\Documents and Settings\%%b\"
Please log in to comment