Thursday, June 23, 2011

Batch File to Create Virtual Disk Drive

Here is the small batch file that lets you create virtual disk drive. This drive doesn't really exist on your computer, it's something like a shortcut to the certain folder on your computer's HDD. The script will look like this:
net use X: \\komp\updat pass /user:user /persistent:yes >Nul 2<&1
set dir=T:\home
set od=X:\
del /Q /F %dir%\*.*
PING -n 1 -w 2000 2>NUL | FIND "TTL=" >NUL
copy /Y %od%\*.* %dir%
As far as you can see, first of all we check for existence of a virtual drive with the physical letter. If this drive doesn't exist, we create it. Finally we copy some files on it.

Tuesday, June 21, 2011

Retrieving Path to the Start-Up Folder

Sometimes you need to place something in Windows start-up folder. Well, it is not hard to do it, but first of all you need to know where this folder is situated. Fortunately, it's not hard, either. Here is the script that lets you retrieve path to the start-up folder:
for /f "tokens=2*" %%i in ('reg query "hkcu\software\microsoft\windows\currentversion\explorer\shell folders" /v ;Startup ^|find /i "startup"') do @set "startfolder=%%j"
echo %startfolder%
You can use this example to create scripts with the help of our powerful batch files editor. Hope you'll find this post useful.

Monday, June 13, 2011

Passing the Current Date to XCOPY

XCOPY is a really useful console command that allows you to make copies of files in a fast and easy way. One of the parameters of this command is '/d':

/d[:mm-dd-yyyy] : Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.

If you need to pass the current date to this command, you'll be surprised: on some configurations of the operating system %date% returns the current date in format, while XCOPY requires mm-dd-yyyy. What to do? Here is some batch code that helps you to solve this problem:

@echo off
set "dd=%date:~0,2%"
set "mm=%date:~3,2%"
set "yy=%date:~-2%"
xcopy c:\*.txt c:\temp /d:%mm%-%dd%-%yy%

You can use this code in your batch files that can be written with the help of our award-winning batch files editor. Hope you'll find this information useful.

Friday, June 10, 2011

Batch File to Check Internet Connection

It's useful to create a small batch file that will check your internet connection and restart the computer if there is no connection at the moment. Of course, nobody restricts you to reset the connection parameters or perform any other actions instead of rebooting the computer. You can take the example below and modify it with help of our award-winning batch files editor.
So here is the script to solve the problem described above:
@echo off

if errorlevel 1 shutdown -r -f -t 0
As far as you can see, the way to check the connection is really simple: we just ping Mental Works Computing Software's site and reboot if it is not available. You can use Google or Yahoo! instead if you prefer.

Saturday, June 4, 2011

Moving a File One Level Upper

We were asked via e-mail about moving files one level upper. Suppose this short example will be useful for everyone:
MOVE 1.ext ..\1.ext
Of course, the file to be moved and the batch script have to be placed in the same folder.