Solved

Batch Script to find out if a folder exists

Posted on 2008-10-28
3
1,770 Views
Last Modified: 2012-05-05
I am trying to make a simple batch script for windows to find out if a user's folder exists on share on a server. If the folder does not exist, I want it to create one with the user's username. Here is what I have so far.

if not exist \\server\\sharedfolder\%username% md \\server\sharedfolder\%username%

Basically I want to run this as a log on script so a each user can have their own folder on a server, some already have one, so that is why I need to check to see if they have one or not.
0
Comment
Question by:Hector7869
  • 2
3 Comments
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 22824030
Assuming that users have sufficient permissions on sharedfolder to create a new folder then that command should work fine.
0
 

Author Comment

by:Hector7869
ID: 22824278

Thats what I thought, for some odd reason it will not make a new folder in my script. If I isolate it and put in a sperate batch file it works, but in my overall script is does not. Here is what the whole batch file looks like. It should check the folder existence first and then create one if it is not there. Then map that folder on the computer.

if not exist \\server4\archive\%username% md \\server4\archive\%username%
 

net use i: \\server2\activefile /user:domain\%username%
net use j: \\server2\archfile /user:domain\%username%
net use t: \\server1\team /user:domain\%username%
net use m: \\server3\users$\%username% /user:domain\%username%
net use l: \\server4\Archive\%username% /user:domain\%username%
 
0
 

Author Comment

by:Hector7869
ID: 22824388
Hmm... I don't know what happened but now it works, I did reset the permission on the shared folder, so mabey that was it. Thanks
0

Featured Post

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.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

821 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