How to create a folder based on user input?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
abacabb
Posts: 2
Joined: 07 Feb 2011 15:41

How to create a folder based on user input?

#1 Post by abacabb » 07 Feb 2011 15:45

I need to write a script that creates folders based on what a user wants. For instance, I want them to be able to execute the batch file, and be prompted to enter the name of the folder to be created. Once a name is entered, the user hits ok and the folder structure is created.

Also, if possible, I needed the script to add/modify NTFS permissions for the folders it creates. Some of the permissions will be permissions that have nothing to do with the user that is executing the script. The user will also be a normal user with standard user privileges. Is there a way to have the script add permissions that have nothing to do with the user? I'm guessing that the script would have to run under a user account that has the necessary privileges. The only way I was able to think of how to do this was with a scheduled task, where the credentials are stored within the job with the user having no access to the actual credentials.

Any ideas?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to create a folder based on user input?

#2 Post by aGerman » 07 Feb 2011 16:38

First half of your question:
Use SET /P for input and MD for creating a folder.

Code: Select all

@echo off &setlocal
set /p "folder=Enter the folder name to be created: "
md "%folder%" ||(pause &goto :eof)


Concerning the second half of your question:
I'm not sure what you're looking for. Have a look at ATTRIB and CACLS.

Regards
aGerman

abacabb
Posts: 2
Joined: 07 Feb 2011 15:41

Re: How to create a folder based on user input?

#3 Post by abacabb » 08 Feb 2011 07:37

aGerman wrote:First half of your question:
Use SET /P for input and MD for creating a folder.

Code: Select all

@echo off &setlocal
set /p "folder=Enter the folder name to be created: "
md "%folder%" ||(pause &goto :eof)


Concerning the second half of your question:
I'm not sure what you're looking for. Have a look at ATTRIB and CACLS.

Regards
aGerman



This script seems great. But I forgot to mention that there is a specific path where the folder needs to be created. How would I include that path?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to create a folder based on user input?

#4 Post by aGerman » 08 Feb 2011 08:49

Just prepend it:

Code: Select all

md "D:\somewhere\%folder%" ||(pause &goto :eof)

Regards
aGerman

Post Reply