Navigation

Search

Categories

On this page

Append Location to Path Environment Variable
Setting up a filename for with the current time in a batch script
go somewhere new

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 120
This Year: 1
This Month: 0
This Week: 0
Comments: 40

Sign In
Pick a theme:

# Monday, December 18, 2006
Monday, December 18, 2006 12:43:28 PM (Mountain Standard Time, UTC-07:00) ( All things Microsoft | Code )

More DOS Scripting goodness. This snippet appends some arbitrary location to your PATH variable, so you can call the executables inside of it.

@ECHO OFF
ECHO %PATH% | FIND /I "C:\Folder1\Folder2\Folder with Spaces\bin\Release"
IF ERRORLEVEL 1 SET PATH=%PATH%;C:\Folder1\Folder2\Folder with Spaces\bin\Release

That, ladies and gentleman, will save you minutes of grief. Isn't that what it's all about anyway? makes it all worth while.

Comments [0] | | # 
# Monday, December 11, 2006
Monday, December 11, 2006 1:01:53 PM (Mountain Standard Time, UTC-07:00) ( Code )

I've found myself using this pattern alot lately. I figured I'd post it for posterity.


@ECHO OFF

SET NOWD=%DATE%
SET mm=%NOWD:~4,2%
SET dd=%NOWD:~7,2%
SET yyyy=%NOWD:~10,4%

:: ECHO mm=%mm%
:: ECHO dd=%dd%
:: ECHO yyyy=%yyyy%

SET NOWT=%TIME%
SET hour=%TIME:~0,2%
SET min=%TIME:~3,2%
SET sec=%TIME:~6,2%
SET ms=%TIME:~9,2%

:: ECHO NOWT=%NOWT%
:: ECHO hour=%hour%
:: ECHO min=%min%
:: ECHO sec=%sec%
:: ECHO ms=%ms%

SET LOGFILENAME=%yyyy%%mm%%dd%_%hour%%min%%sec%%ms%.txt

:: ECHO %LOGFILENAME%

:: make sure to use a double arrow to append, not 'create'

ECHO %DATE% - %TIME% >> %LOGFILENAME%

ECHO Whatever your program should do >> %LOGFILENAME%

 

Comments [0] | | # 
# Friday, October 27, 2006
Friday, October 27, 2006 12:32:26 PM (Mountain Daylight Time, UTC-06:00) ( )

Open your command shell in Windows.

Start -> Run, CMD, <enter>

Go to a different drive, say, the D: volume, to a folder called \foo\bar

this might look like cd D:\foo\bar

Wait, I thought I said, CD, change directory.... what gives, I didn't go anywhere. When I say go, I mean go.

Here's how I go..

GO.CMD


@ECHO OFF
:: Change to 1 to display messages
SET DEBUG=0

:: Make sure there is a parameter
IF [%1]==[] GOTO MissingDir

:: If parameter 1 is a directory, it will have a nul file in it
:: If there is no nul, it's a file, not a directory
IF NOT EXIST %1\nul GOTO NotDir

:: Change working drive
:CWD
IF %DEBUG%==1 (
  ECHO %~d1
)
%~d1

:: Change working path
:CWP
cd "%~pn1"
GOTO :EOF

:: Missing a parameter
:MissingDir
ECHO You did not specify a place to go to
GOTO :Usage

:: Invalid Parameter
:NotDir
ECHO You specified a file, or an invalid directory
GOTO :EOF

:Usage
go.cmd DRIVE:\FULL\PATH\TO\FOLDER
GOTO :EOF

:End

Now, you can go anywhere, really...


Edit (12/18/2006)

This is really helpful, but I found myself using far too many keystrokes to open a console at the location in my clipboard.

Start + R -> cmd -> {ENTER} -> GO{SPACE}, ALT + E + P, {ENTER}... thats 12 keys to press to do this

Added an additional file to my %USERHOME% to automate this.

%USERHOME%\cgo.bat

cmd /k "c:\utils\go.cmd %1 && cls"

Now we're more like

Start + R -> cgo {SPACE} CTRL + V {ENTER}... Thats 9 keys. Thats a 25% reduction, and well worth my time in the one line script & the time documenting.

This saves me 1-3 seconds time I use it (average of 32)... amazing.

 

 

Comments [0] | | #