3

Can someone please tell me how to create new folders on desktop with a batch script?

I can't find any simple tutorials on the internet. I just want a straightforward script that creates folders on my desktop.

1
  • create folder with what name?
    – MAKZ
    Feb 15, 2014 at 4:58

4 Answers 4

3

There is an environment variable named: "USERPROFILE"

This variable holds the path of your "home" directory under the "Users" folder on the drive where Windows is installed.

If you open a command prompt window, and type: echo "%USERPROFILE%", you will see something like:

C:\>echo "%USERPROFILE%"
"C:\Users\your-user-name"

This will also be available as: %HOMEDRIVE%%HOMEPATH% where:

HOMEDRIVE=C:
HOMEPATH=\Users\your-user-name

This folder is the Parent folder for your "Desktop" folder. So, if you wanted to create a folder named "MyNewFolder", on your Desktop from a command window or a batch script, the command would look like this:

C:\>md "%USERPROFILE%\Desktop\MyNewFolder"

These variables (USERPROFILE, HOMEDRIVE, HOMEPATH) are available on Windows 7 (and probably also Windows Vista and Windows 8). For Windows XP and Windows 98, this would have been found under the C:\Documents and Settings folder.

0
1

Here's how I would do it:

  1. Install Cygwin
  2. Open up Notepad
  3. In the blank document, type:

    #!/bin/bash
    mkdir C:\path\to\dersired\directory
    
  4. Hit Ctrl+S
  5. For filetype, choose All files
  6. Save it
  7. Open a command prompt
  8. Type in: C:\cygwin\bin\bash C:\path\to\script\script.sh

You can put other stuff in the bash script too.

4
  • 5
    maybe installing Cygwin isn't the simplest solution to this question.
    – stib
    Feb 15, 2014 at 6:05
  • @stib That's probably true, but I feel like having Cygwin installed would have tremendous value in the future as well.
    – evamvid
    Feb 15, 2014 at 6:07
  • 2
    So would wiping the Windows partition and installing Linux, or learning Lisp so you could write a program to do it. But not a simple solution to the problem.
    – stib
    Feb 15, 2014 at 6:10
  • True! I totally agree =)
    – evamvid
    Feb 16, 2014 at 6:01
1

Write this code in a text file, rename it to [someFilename].bat, and save the file on the desktop:

@echo off
set /p x= 
mkdir %x%

Double-click it, and you will be prompted for input. Enter the desired folder name, and then press enter on the keyboard.

0

Some operating systems can't find the path when using %userprofile% with cd, but this one seems to work on all Windows versions.

@echo off
: start
cd "%systemdrive%/documents and settings/%username%/desktop"
set /p x= name of folder :
md %x%
cls && goto start

Save the .bat file anywhere, and run it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .