Solved

Create the same folder in everyone's home folder

Posted on 2013-11-11
6
328 Views
Last Modified: 2013-11-11
Hi,

I would like a script that will create the same folder in every user's home area. So I would like to create "Folder1" in \\server1\user1\Documents\   \\server1\user2\Documents   \\server1\user9999\Documents ...

But only create this folder if it doesn't already exist.

Is this possible?

Regrads
0
Comment
Question by:Net-Eng99
6 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 39638516
Try this; just set the variables "UserShare" to the root of the user folders, and "CreateFolder" to whatever path and folder you want to create under the actual UserXXX folder.
The script is currently in test mode and will only display the "md" commands it would normally run. Remove the uppercase ECHO before "md" in line 9 to run it for real:
@echo off
setlocal
REM UNC to the root of the User folder:
set UserShare=\\server1\UserShare
REM Folder to create under each user's home folder:
set CreateFolder=Documents\Folder 1
for /d %%a in ("%UserShare%\*.*") do (
	echo Processing %%a ...
	if not exist "%%a\%CreateFolder%" ECHO md "%%a\%CreateFolder%"
)

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39638543
Assuming you can get to the server console, this should do it...remove the 'echo' on the last line to make it happen.
If you can't get to the console, map a network drive to the c$ of the remote server:
net use L: \\server1\c$
then adjust the 2nd line of the code to read
cd /d L:\users


@echo off
cd /d c:\users

for /f "delims=" %%a in ('dir /ad /b') do call :process "%%~fa"
goto :eof

:process
set fld=%1

if /i "%fld:~10,-1%" == "All Users" goto :eof
if /i "%fld:~10,-1%" == "Default User" goto :eof
if /i "%fld:~10,-1%" == "Public" goto :eof

echo Creating folder for %fld%
if not exist %fld:~0,-1%\Documents\Folder1" echo md %fld:~0,-1%\Documents\Folder1"

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39638544
Bah - didn't know oBdA was awake...forgot to refresh, sorry. :^)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 39638565
Could be done right at a command line with a simple command like:

for /D %F in ("\\servername\basedir\*.*") do (md "%~F\Documents\Folder1" >NUL 2>NUL)

Open in new window

or in a BAT file as:

for /D %%F in ("\\servername\basedir\*.*") do (md "%%~F\Documents\Folder1" >NUL 2>NUL)

Open in new window

~bp
0
 

Author Comment

by:Net-Eng99
ID: 39638803
@oBdA thanks for your solution, I tried that one and it worked perfectly!

Regards
0
 

Author Closing Comment

by:Net-Eng99
ID: 39638805
Spot on solution - excellent!
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question