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.
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.
Here's how I would do it:
In the blank document, type:
#!/bin/bash
mkdir C:\path\to\dersired\directory
All files
C:\cygwin\bin\bash C:\path\to\script\script.sh
You can put other stuff in the bash script too.
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.
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.