Skip navigation

JSI Tip 1744. How do I copy files to every user's home directory?


HomeCopy.bat uses only standard commands. It assumes that each user's home directory has a common parent folder, as in:

      c:\users
      c:\users\user1
      c:\users\user2

The syntax is:

HomeCopy <Parent Folder> file1\[,file2,file3,....fileN\]

HomeCopy.bat contains:

@echo off
if NOT \{%1\}

\{\} goto begin if NOT \{%2\}

\{\} goto begin :syntax @echo Syntax: HomeCopy Parent_Folder File1\[,file2,file3,.....filen\] goto end :finish endlocal goto end :begin setlocal if NOT EXIST %1 goto syntax set parent=%1 set parent=%parent:"=% :loop Shift If \{%1\}==\{\} goto finish if NOT EXIST %1 goto syntax set filefull=%1 set file=%~nx1 for /f "Tokens=*" %%i in ('dir "%parent%" /B /AD') do call :parse "%%i" goto loop :parse set child=%1 set child=%child:"=% if exist "%parent%\%child%\%file%" del /q "%parent%\%child%\%file%" copy %filefull% "%parent%\%child%" :end

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish