Get the directory of a file in the Windows CLI

When you script batch files it is very important that you know in which path you are. Especially when you make relative file and folder operations.

C:Userssyss>echo %cd%

As you can see the current workingdirectory ist C:userssyss

When you make a relative file operation, let’s say to …anotheruser it is very important that you have not been forced in another directory e.g. C:windowssystem32.

If you try to to access your desired directory from the system32 folder you will get an error. (or maybe access a directory with the same name, but located at another place)

Most commonly you are forced in another directory when you start batch files from an UNC path. Some companies map “My Documents” to a server share which resolves into \serverusersusername

The thing is that these UNC paths are not supported, but only with a registrypatch. I think patching every client is way too much work and instead of this just put this header in every of your batch files

@echo off
setLocal EnableDelayedExpansion
set workingdir=%~dp0
set workingdir=!workingdir:~0,-1!
pushd !workingdir!

%~dp0 is an extended command, original it would be %0 which is the name of the batchfile. Adding ~dp inbetween resolves the path of the batchfile. Let’s say it would be \serveruserssyss

As you can see there is an trailing slash at the end of the path. In most cases it does not matter, but if you plan to make more folder operations like mounting a network drive it is important that you remove this very slash.

net use Y: \serveruserssyss will not work because Windows can’t interpret this as a valid networkshare nor directory. You might know that directories are special files. Obviously this very file (directory) is only found if you address it directly without slash.

This is a good way to remove the last X characters of a string.

set workingdir=!workingdir:~0,-1!

In fact the content of the variable will be altered and then saved into the variable again. This command goes from position 0 (index origin 0) to the last but one character (-1)

I will then change the directory with pushd and the network path. Pushd implicitly makes a net use to the UNC path (or normal path) with a Drive Letter from Z down to A. It skips a letter if it is already taken. If there is no driveletter available windows makes a strange output:

B:syss>pushd \serverUserssyss
" "
CMD does not support UNC paths as working directory. (free translation)

Do not forget to pop out of your directories:


and you are done.

Unpacking CuBox from Solid Run Ltd.

It has been exactly 4 Month since I ordered my CuBox and finally it is here. A nice litte Computer in the formfactor of nearly a cube.

There have been a lot of questions on their official Forum about additional taxes and customs. Here’s some information:

  • Original price: 99 Euro
  • Shipping to Austria / Europe: 30 Euro
  • Taxes / Customs: 25,80 Euro

These three make a total of 154,80 Euro. Still affordable I think.

Front side of the original package

Back side of the original package

Customs letter (25,80 Euro on a base of 129 Euro worth= 20%)

Cubox Package

First opening of the package

Letters removed

Contents (Cubox & Power adapter)

Cubox with all its ports

Cubox upside down (rubber feed)

Power Adapter

Micro SD Card (built in)

Power LED and IR receiver (semitransparent material)


The next days I will post about the inner life of the CuBox (when I find my HDMI cable). Interessting will be the boottime, program start times and so on. Also I will try some things like playing music and videos and maybe playing a 3D game, we will see. Another thing is the real power consumption on idle and on full CPU workload.

Stay tuned!


Remove protection from password protected document without password

This is somethings special I discoverd in some spare time.

I once had an Microsoft Word document which was protected by a password. Unfortunately the password was lost and I needed to edit this document.

Here you can read about Microsoft Office Document Protection

But this is how you can remove the protection without password:

  1. Open the Document and save as DOCX. Close Word.
  2. Open the Document and save as RTF. Close Word.
  3. Open the Document and save as DOC. Close Word
  4. Open the Document and choose as filetype DOT but instead of saving the Document you click the menu ‘Tools’ on the left and select ‘General Options’
  5. Select ‘Remove protection’ (you do not need to enter the password)
  6. Save the Document. Close Word
  7. Open the Document again and save as preferred filetype.

The strange thing is that you have to save the document in this very order und must close it after each saving process. This only works with word files, since you cannot save an Excel file as RTF.

I think the information about the password protection gets lost anywhere in the savingprocesses. Maybe Word does not write all the information from the RAM correctly back to disk.

Tested on Microsoft Office Professional Plus 2007