Batch – Choose a directory by number

If you like your users to manually choose a directory in you filesystem but do not want them to type in the complete name of it, just use following script.

@echo off
setLocal EnableDelayedExpansion
set i=0
set c=0
for /f "tokens=*" %%a in ('dir C:temp /AD /b') do (
 set /a i+=1
 set dir!i!=%%a
 if !i! leq 9 (echo [ !i!] %%a)
 if !i! gtr 9 (echo [!i!] %%a)
set /p choice="Please choose: "
if !dir%choice%! equ ^!dir^%choice^%^! echo Your choice !dir%choice%! was not found. &goto choose
echo Your choice was !dir%choice%!
If the users executes the script there is a list of all directories created. If the user chooses a directory and before this very directory was delete the value of !dir%choice%! will be exactly the name of the value. This is why i catched this exception. Not a very common case but you could never know! 🙂
This works up to 99 directories (no directories not tested) otherwise the menu choice would not look that fine.

Batchfile – Selfdelete

Here is a simple code how to delete a batchfile after running. Mostly used to erase traces and not having so much trash on your filesystem

@echo off
cmd /q /c del %0
  • @echo off turns off the commandoutput
  • cmd launches a new commandline window
  • /q stands for quiet like @echo off
  • /c stands for a command you like to execute
  • del stands for delete
  • %0 stands for the batchfile itself
  • the exit is not needed but you can add it if you like so

Adding a custom repository to aptitude: launchpad

Sometimes you need to install software on your linux box, which couldn’t be found over the normal repositories.

Me for example tried to install XBMC

add-apt-repository ppa:team-xbmc

First i got this error:

Error: can't find signing_key_fingerprint at <a href=""></a>

I spelt XBMC incorrect (wrong: XMBC)

So if you spelt your software correctly or copyed your commandlines from a reliable source the following will happen:

Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /etc/apt/secring.gpg --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver --recv xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

So when you execute your add-apt-repositry command it implicity executes the above command. As you can see the gpg (i always mix this up with pgp) launches with a lot of parameters which you cannot remember if you are not that interessted.

And as you know problems always come in packs just look at the lines below

gpg: requesting key xxxxxxx from hkp server
gpg: keyserver timed out
gpg: keyserver receive failed: keyserver error

The thing is that GPG cannot go over https. More to read here. So we need to edit the preferences that GPG is forced to get the keys over http. Just edit with following line

vim /usr/share/pyshared/softwareproperties/

Search for


and edit it to


Edit this back when you are done installing your software from launchpad. Otherwise you are getting your software insecurely and aptitude is always nagging about it 😉

gpg: requesting key 91E7EE5E from hkp server
gpg: key 91E7EE5E: public key "Launchpad PPA for XBMC for Linux" imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)

Execute your last command and you will see the above. And for the fact, that I am very talented to missspell something here is another error I got:

W: Failed to fetch  404  Not Found

But this one is easy. I only entered a wrong PPA address before.

Just go to this file

vim /etc/apt/sources.list.d/
and delete all the wrong lines out of it.
So that should it be. Stay entertained!