Move the libmtp source from jumper to external.

Change-Id: I06bce6628cf809af6f7125c8fb4115bafd7c6c87
diff --git a/examples/Makefile.am b/examples/Makefile.am
new file mode 100644
index 0000000..101141c
--- /dev/null
+++ b/examples/Makefile.am
@@ -0,0 +1,34 @@
+bin_PROGRAMS=connect detect tracks files hotplug \
+	folders trexist playlists getplaylist \
+	format albumart albums newplaylist emptyfolders \
+	thumb reset
+
+connect_SOURCES=connect.c delfile.c getfile.c newfolder.c \
+	sendfile.c sendtr.c pathutils.c pathutils.h \
+	util.c util.h common.h
+detect_SOURCES=detect.c util.c util.h common.h
+tracks_SOURCES=tracks.c util.c util.h common.h
+files_SOURCES=files.c util.c util.h common.h
+hotplug_SOURCES=hotplug.c util.c util.h common.h
+folders_SOURCES=folders.c util.c util.h common.h
+trexist_SOURCES=trexist.c util.c util.h common.h
+playlists_SOURCES=playlists.c util.c util.h common.h
+getplaylist_SOURCES=getplaylist.c util.c util.h common.h
+newplaylist_SOURCES=newplaylist.c util.c util.h common.h
+format_SOURCES=format.c util.c util.h common.h
+albumart_SOURCES=albumart.c util.c util.h common.h
+albums_SOURCES=albums.c util.c util.h common.h
+emptyfolders_SOURCES=emptyfolders.c util.c util.h common.h
+thumb_SOURCES=thumb.c util.c util.h common.h
+reset_SOURCES=reset.c util.c util.h common.h
+
+AM_CPPFLAGS=-I$(top_builddir)/src
+LDADD=../src/libmtp.la
+EXTRA_DIST=evolution-sync.sh
+
+install-exec-hook:
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-delfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-getfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-newfolder$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendtr$(EXEEXT)
diff --git a/examples/Makefile.in b/examples/Makefile.in
new file mode 100644
index 0000000..875656e
--- /dev/null
+++ b/examples/Makefile.in
@@ -0,0 +1,687 @@
+# Makefile.in generated by automake 1.11 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005, 2006, 2007, 2008, 2009  Free Software Foundation,
+# Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkglibexecdir = $(libexecdir)/@PACKAGE@
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+bin_PROGRAMS = connect$(EXEEXT) detect$(EXEEXT) tracks$(EXEEXT) \
+	files$(EXEEXT) hotplug$(EXEEXT) folders$(EXEEXT) \
+	trexist$(EXEEXT) playlists$(EXEEXT) getplaylist$(EXEEXT) \
+	format$(EXEEXT) albumart$(EXEEXT) albums$(EXEEXT) \
+	newplaylist$(EXEEXT) emptyfolders$(EXEEXT) thumb$(EXEEXT) \
+	reset$(EXEEXT)
+subdir = examples
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/m4/byteorder.m4 \
+	$(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \
+	$(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \
+	$(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/stdint.m4 \
+	$(top_srcdir)/configure.ac
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+	$(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+CONFIG_CLEAN_VPATH_FILES =
+am__installdirs = "$(DESTDIR)$(bindir)"
+PROGRAMS = $(bin_PROGRAMS)
+am_albumart_OBJECTS = albumart.$(OBJEXT) util.$(OBJEXT)
+albumart_OBJECTS = $(am_albumart_OBJECTS)
+albumart_LDADD = $(LDADD)
+albumart_DEPENDENCIES = ../src/libmtp.la
+am_albums_OBJECTS = albums.$(OBJEXT) util.$(OBJEXT)
+albums_OBJECTS = $(am_albums_OBJECTS)
+albums_LDADD = $(LDADD)
+albums_DEPENDENCIES = ../src/libmtp.la
+am_connect_OBJECTS = connect.$(OBJEXT) delfile.$(OBJEXT) \
+	getfile.$(OBJEXT) newfolder.$(OBJEXT) sendfile.$(OBJEXT) \
+	sendtr.$(OBJEXT) pathutils.$(OBJEXT) util.$(OBJEXT)
+connect_OBJECTS = $(am_connect_OBJECTS)
+connect_LDADD = $(LDADD)
+connect_DEPENDENCIES = ../src/libmtp.la
+am_detect_OBJECTS = detect.$(OBJEXT) util.$(OBJEXT)
+detect_OBJECTS = $(am_detect_OBJECTS)
+detect_LDADD = $(LDADD)
+detect_DEPENDENCIES = ../src/libmtp.la
+am_emptyfolders_OBJECTS = emptyfolders.$(OBJEXT) util.$(OBJEXT)
+emptyfolders_OBJECTS = $(am_emptyfolders_OBJECTS)
+emptyfolders_LDADD = $(LDADD)
+emptyfolders_DEPENDENCIES = ../src/libmtp.la
+am_files_OBJECTS = files.$(OBJEXT) util.$(OBJEXT)
+files_OBJECTS = $(am_files_OBJECTS)
+files_LDADD = $(LDADD)
+files_DEPENDENCIES = ../src/libmtp.la
+am_folders_OBJECTS = folders.$(OBJEXT) util.$(OBJEXT)
+folders_OBJECTS = $(am_folders_OBJECTS)
+folders_LDADD = $(LDADD)
+folders_DEPENDENCIES = ../src/libmtp.la
+am_format_OBJECTS = format.$(OBJEXT) util.$(OBJEXT)
+format_OBJECTS = $(am_format_OBJECTS)
+format_LDADD = $(LDADD)
+format_DEPENDENCIES = ../src/libmtp.la
+am_getplaylist_OBJECTS = getplaylist.$(OBJEXT) util.$(OBJEXT)
+getplaylist_OBJECTS = $(am_getplaylist_OBJECTS)
+getplaylist_LDADD = $(LDADD)
+getplaylist_DEPENDENCIES = ../src/libmtp.la
+am_hotplug_OBJECTS = hotplug.$(OBJEXT) util.$(OBJEXT)
+hotplug_OBJECTS = $(am_hotplug_OBJECTS)
+hotplug_LDADD = $(LDADD)
+hotplug_DEPENDENCIES = ../src/libmtp.la
+am_newplaylist_OBJECTS = newplaylist.$(OBJEXT) util.$(OBJEXT)
+newplaylist_OBJECTS = $(am_newplaylist_OBJECTS)
+newplaylist_LDADD = $(LDADD)
+newplaylist_DEPENDENCIES = ../src/libmtp.la
+am_playlists_OBJECTS = playlists.$(OBJEXT) util.$(OBJEXT)
+playlists_OBJECTS = $(am_playlists_OBJECTS)
+playlists_LDADD = $(LDADD)
+playlists_DEPENDENCIES = ../src/libmtp.la
+am_reset_OBJECTS = reset.$(OBJEXT) util.$(OBJEXT)
+reset_OBJECTS = $(am_reset_OBJECTS)
+reset_LDADD = $(LDADD)
+reset_DEPENDENCIES = ../src/libmtp.la
+am_thumb_OBJECTS = thumb.$(OBJEXT) util.$(OBJEXT)
+thumb_OBJECTS = $(am_thumb_OBJECTS)
+thumb_LDADD = $(LDADD)
+thumb_DEPENDENCIES = ../src/libmtp.la
+am_tracks_OBJECTS = tracks.$(OBJEXT) util.$(OBJEXT)
+tracks_OBJECTS = $(am_tracks_OBJECTS)
+tracks_LDADD = $(LDADD)
+tracks_DEPENDENCIES = ../src/libmtp.la
+am_trexist_OBJECTS = trexist.$(OBJEXT) util.$(OBJEXT)
+trexist_OBJECTS = $(am_trexist_OBJECTS)
+trexist_LDADD = $(LDADD)
+trexist_DEPENDENCIES = ../src/libmtp.la
+DEFAULT_INCLUDES = -I.@am__isrc@ -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+am__mv = mv -f
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+	$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+	$(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
+	--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
+	$(LDFLAGS) -o $@
+SOURCES = $(albumart_SOURCES) $(albums_SOURCES) $(connect_SOURCES) \
+	$(detect_SOURCES) $(emptyfolders_SOURCES) $(files_SOURCES) \
+	$(folders_SOURCES) $(format_SOURCES) $(getplaylist_SOURCES) \
+	$(hotplug_SOURCES) $(newplaylist_SOURCES) $(playlists_SOURCES) \
+	$(reset_SOURCES) $(thumb_SOURCES) $(tracks_SOURCES) \
+	$(trexist_SOURCES)
+DIST_SOURCES = $(albumart_SOURCES) $(albums_SOURCES) \
+	$(connect_SOURCES) $(detect_SOURCES) $(emptyfolders_SOURCES) \
+	$(files_SOURCES) $(folders_SOURCES) $(format_SOURCES) \
+	$(getplaylist_SOURCES) $(hotplug_SOURCES) \
+	$(newplaylist_SOURCES) $(playlists_SOURCES) $(reset_SOURCES) \
+	$(thumb_SOURCES) $(tracks_SOURCES) $(trexist_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMTAR = @AMTAR@
+AR = @AR@
+AS = @AS@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DLLTOOL = @DLLTOOL@
+DSYMUTIL = @DSYMUTIL@
+DUMPBIN = @DUMPBIN@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+FGREP = @FGREP@
+GREP = @GREP@
+HAVE_DOXYGEN = @HAVE_DOXYGEN@
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LD = @LD@
+LDFLAGS = @LDFLAGS@
+LIBICONV = @LIBICONV@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIPO = @LIPO@
+LN_S = @LN_S@
+LTLIBICONV = @LTLIBICONV@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+MKDIR_P = @MKDIR_P@
+NM = @NM@
+NMEDIT = @NMEDIT@
+OBJDUMP = @OBJDUMP@
+OBJEXT = @OBJEXT@
+OSFLAGS = @OSFLAGS@
+OTOOL = @OTOOL@
+OTOOL64 = @OTOOL64@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+RANLIB = @RANLIB@
+SED = @SED@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+abs_builddir = @abs_builddir@
+abs_srcdir = @abs_srcdir@
+abs_top_builddir = @abs_top_builddir@
+abs_top_srcdir = @abs_top_srcdir@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_DUMPBIN = @ac_ct_DUMPBIN@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+builddir = @builddir@
+datadir = @datadir@
+datarootdir = @datarootdir@
+docdir = @docdir@
+dvidir = @dvidir@
+effective_target = @effective_target@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+htmldir = @htmldir@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @libdir@
+libexecdir = @libexecdir@
+localedir = @localedir@
+localstatedir = @localstatedir@
+lt_ECHO = @lt_ECHO@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+ms_lib_exe = @ms_lib_exe@
+oldincludedir = @oldincludedir@
+pdfdir = @pdfdir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+psdir = @psdir@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+srcdir = @srcdir@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+top_build_prefix = @top_build_prefix@
+top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+connect_SOURCES = connect.c delfile.c getfile.c newfolder.c \
+	sendfile.c sendtr.c pathutils.c pathutils.h \
+	util.c util.h common.h
+
+detect_SOURCES = detect.c util.c util.h common.h
+tracks_SOURCES = tracks.c util.c util.h common.h
+files_SOURCES = files.c util.c util.h common.h
+hotplug_SOURCES = hotplug.c util.c util.h common.h
+folders_SOURCES = folders.c util.c util.h common.h
+trexist_SOURCES = trexist.c util.c util.h common.h
+playlists_SOURCES = playlists.c util.c util.h common.h
+getplaylist_SOURCES = getplaylist.c util.c util.h common.h
+newplaylist_SOURCES = newplaylist.c util.c util.h common.h
+format_SOURCES = format.c util.c util.h common.h
+albumart_SOURCES = albumart.c util.c util.h common.h
+albums_SOURCES = albums.c util.c util.h common.h
+emptyfolders_SOURCES = emptyfolders.c util.c util.h common.h
+thumb_SOURCES = thumb.c util.c util.h common.h
+reset_SOURCES = reset.c util.c util.h common.h
+AM_CPPFLAGS = -I$(top_builddir)/src
+LDADD = ../src/libmtp.la
+EXTRA_DIST = evolution-sync.sh
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in:  $(srcdir)/Makefile.am  $(am__configure_deps)
+	@for dep in $?; do \
+	  case '$(am__configure_deps)' in \
+	    *$$dep*) \
+	      ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \
+	        && { if test -f $@; then exit 0; else break; fi; }; \
+	      exit 1;; \
+	  esac; \
+	done; \
+	echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/Makefile'; \
+	$(am__cd) $(top_srcdir) && \
+	  $(AUTOMAKE) --foreign examples/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+	@case '$?' in \
+	  *config.status*) \
+	    cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+	  *) \
+	    echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+	    cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+	esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure:  $(am__configure_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4):  $(am__aclocal_m4_deps)
+	cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(am__aclocal_m4_deps):
+install-binPROGRAMS: $(bin_PROGRAMS)
+	@$(NORMAL_INSTALL)
+	test -z "$(bindir)" || $(MKDIR_P) "$(DESTDIR)$(bindir)"
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	for p in $$list; do echo "$$p $$p"; done | \
+	sed 's/$(EXEEXT)$$//' | \
+	while read p p1; do if test -f $$p || test -f $$p1; \
+	  then echo "$$p"; echo "$$p"; else :; fi; \
+	done | \
+	sed -e 'p;s,.*/,,;n;h' -e 's|.*|.|' \
+	    -e 'p;x;s,.*/,,;s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/' | \
+	sed 'N;N;N;s,\n, ,g' | \
+	$(AWK) 'BEGIN { files["."] = ""; dirs["."] = 1 } \
+	  { d=$$3; if (dirs[d] != 1) { print "d", d; dirs[d] = 1 } \
+	    if ($$2 == $$4) files[d] = files[d] " " $$1; \
+	    else { print "f", $$3 "/" $$4, $$1; } } \
+	  END { for (d in files) print "f", d, files[d] }' | \
+	while read type dir files; do \
+	    if test "$$dir" = .; then dir=; else dir=/$$dir; fi; \
+	    test -z "$$files" || { \
+	    echo " $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files '$(DESTDIR)$(bindir)$$dir'"; \
+	    $(INSTALL_PROGRAM_ENV) $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL_PROGRAM) $$files "$(DESTDIR)$(bindir)$$dir" || exit $$?; \
+	    } \
+	; done
+
+uninstall-binPROGRAMS:
+	@$(NORMAL_UNINSTALL)
+	@list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \
+	files=`for p in $$list; do echo "$$p"; done | \
+	  sed -e 'h;s,^.*/,,;s/$(EXEEXT)$$//;$(transform)' \
+	      -e 's/$$/$(EXEEXT)/' `; \
+	test -n "$$list" || exit 0; \
+	echo " ( cd '$(DESTDIR)$(bindir)' && rm -f" $$files ")"; \
+	cd "$(DESTDIR)$(bindir)" && rm -f $$files
+
+clean-binPROGRAMS:
+	@list='$(bin_PROGRAMS)'; test -n "$$list" || exit 0; \
+	echo " rm -f" $$list; \
+	rm -f $$list || exit $$?; \
+	test -n "$(EXEEXT)" || exit 0; \
+	list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \
+	echo " rm -f" $$list; \
+	rm -f $$list
+albumart$(EXEEXT): $(albumart_OBJECTS) $(albumart_DEPENDENCIES) 
+	@rm -f albumart$(EXEEXT)
+	$(LINK) $(albumart_OBJECTS) $(albumart_LDADD) $(LIBS)
+albums$(EXEEXT): $(albums_OBJECTS) $(albums_DEPENDENCIES) 
+	@rm -f albums$(EXEEXT)
+	$(LINK) $(albums_OBJECTS) $(albums_LDADD) $(LIBS)
+connect$(EXEEXT): $(connect_OBJECTS) $(connect_DEPENDENCIES) 
+	@rm -f connect$(EXEEXT)
+	$(LINK) $(connect_OBJECTS) $(connect_LDADD) $(LIBS)
+detect$(EXEEXT): $(detect_OBJECTS) $(detect_DEPENDENCIES) 
+	@rm -f detect$(EXEEXT)
+	$(LINK) $(detect_OBJECTS) $(detect_LDADD) $(LIBS)
+emptyfolders$(EXEEXT): $(emptyfolders_OBJECTS) $(emptyfolders_DEPENDENCIES) 
+	@rm -f emptyfolders$(EXEEXT)
+	$(LINK) $(emptyfolders_OBJECTS) $(emptyfolders_LDADD) $(LIBS)
+files$(EXEEXT): $(files_OBJECTS) $(files_DEPENDENCIES) 
+	@rm -f files$(EXEEXT)
+	$(LINK) $(files_OBJECTS) $(files_LDADD) $(LIBS)
+folders$(EXEEXT): $(folders_OBJECTS) $(folders_DEPENDENCIES) 
+	@rm -f folders$(EXEEXT)
+	$(LINK) $(folders_OBJECTS) $(folders_LDADD) $(LIBS)
+format$(EXEEXT): $(format_OBJECTS) $(format_DEPENDENCIES) 
+	@rm -f format$(EXEEXT)
+	$(LINK) $(format_OBJECTS) $(format_LDADD) $(LIBS)
+getplaylist$(EXEEXT): $(getplaylist_OBJECTS) $(getplaylist_DEPENDENCIES) 
+	@rm -f getplaylist$(EXEEXT)
+	$(LINK) $(getplaylist_OBJECTS) $(getplaylist_LDADD) $(LIBS)
+hotplug$(EXEEXT): $(hotplug_OBJECTS) $(hotplug_DEPENDENCIES) 
+	@rm -f hotplug$(EXEEXT)
+	$(LINK) $(hotplug_OBJECTS) $(hotplug_LDADD) $(LIBS)
+newplaylist$(EXEEXT): $(newplaylist_OBJECTS) $(newplaylist_DEPENDENCIES) 
+	@rm -f newplaylist$(EXEEXT)
+	$(LINK) $(newplaylist_OBJECTS) $(newplaylist_LDADD) $(LIBS)
+playlists$(EXEEXT): $(playlists_OBJECTS) $(playlists_DEPENDENCIES) 
+	@rm -f playlists$(EXEEXT)
+	$(LINK) $(playlists_OBJECTS) $(playlists_LDADD) $(LIBS)
+reset$(EXEEXT): $(reset_OBJECTS) $(reset_DEPENDENCIES) 
+	@rm -f reset$(EXEEXT)
+	$(LINK) $(reset_OBJECTS) $(reset_LDADD) $(LIBS)
+thumb$(EXEEXT): $(thumb_OBJECTS) $(thumb_DEPENDENCIES) 
+	@rm -f thumb$(EXEEXT)
+	$(LINK) $(thumb_OBJECTS) $(thumb_LDADD) $(LIBS)
+tracks$(EXEEXT): $(tracks_OBJECTS) $(tracks_DEPENDENCIES) 
+	@rm -f tracks$(EXEEXT)
+	$(LINK) $(tracks_OBJECTS) $(tracks_LDADD) $(LIBS)
+trexist$(EXEEXT): $(trexist_OBJECTS) $(trexist_DEPENDENCIES) 
+	@rm -f trexist$(EXEEXT)
+	$(LINK) $(trexist_OBJECTS) $(trexist_LDADD) $(LIBS)
+
+mostlyclean-compile:
+	-rm -f *.$(OBJEXT)
+
+distclean-compile:
+	-rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/albumart.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/albums.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/connect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/delfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/detect.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/emptyfolders.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/files.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/folders.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/format.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getplaylist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hotplug.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newfolder.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/newplaylist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pathutils.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/playlists.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/reset.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendfile.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/sendtr.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/thumb.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tracks.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/trexist.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Po@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@	$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'`
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@	$(LTCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
+@am__fastdepCC_TRUE@	$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+	-rm -f *.lo
+
+clean-libtool:
+	-rm -rf .libs _libs
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+	list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	mkid -fID $$unique
+tags: TAGS
+
+TAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	set x; \
+	here=`pwd`; \
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	shift; \
+	if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \
+	  test -n "$$unique" || unique=$$empty_fix; \
+	  if test $$# -gt 0; then \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      "$$@" $$unique; \
+	  else \
+	    $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+	      $$unique; \
+	  fi; \
+	fi
+ctags: CTAGS
+CTAGS:  $(HEADERS) $(SOURCES)  $(TAGS_DEPENDENCIES) \
+		$(TAGS_FILES) $(LISP)
+	list='$(SOURCES) $(HEADERS)  $(LISP) $(TAGS_FILES)'; \
+	unique=`for i in $$list; do \
+	    if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+	  done | \
+	  $(AWK) '{ files[$$0] = 1; nonempty = 1; } \
+	      END { if (nonempty) { for (i in files) print i; }; }'`; \
+	test -z "$(CTAGS_ARGS)$$unique" \
+	  || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+	     $$unique
+
+GTAGS:
+	here=`$(am__cd) $(top_builddir) && pwd` \
+	  && $(am__cd) $(top_srcdir) \
+	  && gtags -i $(GTAGS_ARGS) "$$here"
+
+distclean-tags:
+	-rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+	@srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \
+	list='$(DISTFILES)'; \
+	  dist_files=`for file in $$list; do echo $$file; done | \
+	  sed -e "s|^$$srcdirstrip/||;t" \
+	      -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \
+	case $$dist_files in \
+	  */*) $(MKDIR_P) `echo "$$dist_files" | \
+			   sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \
+			   sort -u` ;; \
+	esac; \
+	for file in $$dist_files; do \
+	  if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+	  if test -d $$d/$$file; then \
+	    dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \
+	    if test -d "$(distdir)/$$file"; then \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+	      cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \
+	      find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \
+	    fi; \
+	    cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \
+	  else \
+	    test -f "$(distdir)/$$file" \
+	    || cp -p $$d/$$file "$(distdir)/$$file" \
+	    || exit 1; \
+	  fi; \
+	done
+check-am: all-am
+check: check-am
+all-am: Makefile $(PROGRAMS)
+installdirs:
+	for dir in "$(DESTDIR)$(bindir)"; do \
+	  test -z "$$dir" || $(MKDIR_P) "$$dir"; \
+	done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+	@$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+	$(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+	  install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+	  `test -z '$(STRIP)' || \
+	    echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+	-test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+	-test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES)
+
+maintainer-clean-generic:
+	@echo "This command is intended for maintainers to use"
+	@echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-binPROGRAMS clean-generic clean-libtool mostlyclean-am
+
+distclean: distclean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+	distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+html-am:
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-dvi: install-dvi-am
+
+install-dvi-am:
+
+install-exec-am: install-binPROGRAMS
+	@$(NORMAL_INSTALL)
+	$(MAKE) $(AM_MAKEFLAGS) install-exec-hook
+install-html: install-html-am
+
+install-html-am:
+
+install-info: install-info-am
+
+install-info-am:
+
+install-man:
+
+install-pdf: install-pdf-am
+
+install-pdf-am:
+
+install-ps: install-ps-am
+
+install-ps-am:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+	-rm -rf ./$(DEPDIR)
+	-rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-binPROGRAMS
+
+.MAKE: install-am install-exec-am install-strip
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-binPROGRAMS \
+	clean-generic clean-libtool ctags distclean distclean-compile \
+	distclean-generic distclean-libtool distclean-tags distdir dvi \
+	dvi-am html html-am info info-am install install-am \
+	install-binPROGRAMS install-data install-data-am install-dvi \
+	install-dvi-am install-exec install-exec-am install-exec-hook \
+	install-html install-html-am install-info install-info-am \
+	install-man install-pdf install-pdf-am install-ps \
+	install-ps-am install-strip installcheck installcheck-am \
+	installdirs maintainer-clean maintainer-clean-generic \
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-libtool pdf pdf-am ps ps-am tags uninstall \
+	uninstall-am uninstall-binPROGRAMS
+
+
+install-exec-hook:
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-delfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-getfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-newfolder$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendfile$(EXEEXT)
+	ln -f -s $(DESTDIR)$(bindir)/mtp-connect$(EXEEXT) $(DESTDIR)$(bindir)/mtp-sendtr$(EXEEXT)
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/examples/albumart.c b/examples/albumart.c
new file mode 100644
index 0000000..61b056e
--- /dev/null
+++ b/examples/albumart.c
@@ -0,0 +1,160 @@
+/** 
+ * \file albumart.c
+ * Example program to send album art.
+ *
+ * Copyright (C) 2006 Andy Kelk <andy@mopoke.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "config.h"
+#include "common.h"
+#include "string.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+
+static void usage(void) {
+  printf("Usage: albumart -i <fileid/trackid> -n <albumname> <imagefile>\n");
+  exit(0);
+}
+
+int main (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  LIBMTP_mtpdevice_t *device = NULL;
+  int idcount = 0;
+  int fd;
+  uint32_t *ids = NULL;
+  uint32_t *tmp = NULL;
+  uint64_t filesize;
+  char *imagedata = NULL;
+  char *albumname = NULL;
+  char *path = NULL;
+  char *rest;
+  struct stat statbuff;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "hn:i:")) != -1 ) {
+    switch (opt) {
+    case 'h':
+      usage();
+    case 'i':
+      idcount++;
+      if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) {
+        printf("realloc failed\n");
+        return 1;
+      }
+      ids = tmp;
+      ids[(idcount-1)] = strtoul(optarg, &rest, 0);
+      break;
+    case 'n':
+      albumname = strdup(optarg);
+      break;
+    default:
+      usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+
+  if ( argc != 1 ) {
+    printf("You need to pass a filename.\n");
+    usage();
+  }
+
+  if ( albumname == NULL) {
+    printf("You need to supply an album name.\n");
+    usage();
+  }
+
+  if (idcount == 0) {
+    printf("You need to supply one or more track IDs\n");
+    usage();
+  }
+
+  path = argv[0];
+
+  if ( stat(path, &statbuff) == -1 ) {
+    fprintf(stderr, "%s: ", path);
+    perror("stat");
+    exit(1);
+  }
+  filesize = (uint64_t) statbuff.st_size;
+  imagedata = malloc(filesize * sizeof(uint8_t));
+
+#ifdef __WIN32__
+  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
+#else
+  if ( (fd = open(path, O_RDONLY)) == -1) {
+#endif
+    printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
+    return 1;
+  }
+  else {
+    read(fd, imagedata, filesize);
+    close(fd);
+  }
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  LIBMTP_filesampledata_t *albumart = LIBMTP_new_filesampledata_t();
+  albumart->data = imagedata;
+  albumart->size = filesize;
+  albumart->filetype = LIBMTP_FILETYPE_JPEG;
+
+  LIBMTP_album_t *album = LIBMTP_new_album_t();
+  album->name = albumname;
+  album->no_tracks = idcount;
+  album->tracks = ids;
+  album->parent_id = 0;
+  album->storage_id = 0;
+  int ret = LIBMTP_Create_New_Album(device,album);
+  if (ret == 0) {
+    ret = LIBMTP_Send_Representative_Sample(device,album->album_id, albumart);
+    if (ret != 0) {
+      printf("Couldn't send album art\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+  }
+  else {
+    printf("Couldn't create album object\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  }
+
+  LIBMTP_destroy_filesampledata_t(albumart);
+  LIBMTP_destroy_album_t(album);
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
+
diff --git a/examples/albums.c b/examples/albums.c
new file mode 100644
index 0000000..a653126
--- /dev/null
+++ b/examples/albums.c
@@ -0,0 +1,99 @@
+/** 
+ * \file albums.c
+ * Example program that lists the albums on the device.
+ *
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+
+static void dump_albuminfo(LIBMTP_album_t *album)
+{
+  printf("Album ID: %d\n",album->album_id);
+  printf("    Parent ID:   %d\n",album->parent_id);
+  printf("    Name:   %s\n",album->name);
+  printf("    Artist: %s\n", album->artist);
+  printf("    Composer:  %s\n", album->composer);
+  printf("    Genre:  %s\n", album->genre);
+  printf("    Tracks: %d\n\n",album->no_tracks);
+}
+
+int main () {
+  LIBMTP_mtpdevice_t *device_list, *iter;
+
+  LIBMTP_Init();
+    
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  switch(LIBMTP_Get_Connected_Devices(&device_list))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-albums: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-albums: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-albums: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-albums: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-albums: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device_list; iter != NULL; iter = iter->next)
+  {
+    char *friendlyname;
+    LIBMTP_album_t *album_list, *album, *tmp;
+    
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Retrieving Albums on Device with name: (NULL)\n");
+    } else {
+      printf("Retrieving Albums on Device with name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+    
+    album_list = LIBMTP_Get_Album_List(iter);
+    album = album_list;
+    while(album != NULL)
+    {
+      dump_albuminfo(album);
+      tmp = album;
+      album = album->next;
+      LIBMTP_destroy_album_t(tmp);
+    }
+  }
+  
+  LIBMTP_Release_Device_List(device_list);
+  printf("OK.\n");
+  return 0;
+}
+
diff --git a/examples/common.h b/examples/common.h
new file mode 100644
index 0000000..ec41bb8
--- /dev/null
+++ b/examples/common.h
@@ -0,0 +1,34 @@
+/** 
+ * \file common.h
+ * These headers are used by absolutely all sample programs.
+ * Special quirks that apply to all samples go here.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <libmtp.h>
+#ifndef _MSC_VER
+#include <config.h>
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+#include <unistd.h>
+#endif
+#else
+// Only if using MSVC...
+#include "..\windows\getopt.h"
+#endif
diff --git a/examples/connect.c b/examples/connect.c
new file mode 100644
index 0000000..99945eb
--- /dev/null
+++ b/examples/connect.c
@@ -0,0 +1,169 @@
+/** 
+ * \file connect.c
+ * Main programs implementing several utilities in one.
+ *
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ * Copyright (C) 2008-2009 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include <stdlib.h>
+#include <libgen.h>
+#include <getopt.h>
+#include <string.h>
+#include "common.h"
+#include "util.h"
+#include "pathutils.h"
+
+LIBMTP_folder_t *folders;
+LIBMTP_file_t *files;
+LIBMTP_mtpdevice_t *device;
+
+void usage(void);
+void split_arg(char *,char **, char **);
+void delfile_function(char *);
+void delfile_command(int, char **);
+void delfile_usage(void);
+int sendtrack_function(char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t);
+void sendtrack_command (int, char **);
+void sendtrack_usage(void);
+void sendfile_function(char *,char *);
+void sendfile_command(int, char **);
+void sendfile_usage(void);
+void getfile_function(char *,char *);
+void getfile_command(int, char **);
+void getfile_usage(void);
+void newfolder_function(char *);
+void newfolder_command(int,char **);
+void newfolder_usage(void);
+
+void
+split_arg(char * argument, char ** part1, char ** part2)
+{
+  char *sepp;
+  *part1 = NULL;
+  *part2 = NULL;
+
+  sepp = argument + strcspn(argument, ",");
+  sepp[0] = '\0';
+  *part1 = argument;
+  *part2 = sepp+1;
+}
+
+void
+usage(void)
+{
+  printf("Usage: connect <command1> <command2>\n");
+  printf("Commands: --delete [filename]\n");
+  printf("          --sendfile [source] [destination]\n");
+  printf("          --sendtrack [source] [destination]\n");
+  printf("          --getfile [source] [destination]\n");
+  printf("          --newfolder [foldername]\n");
+}
+
+
+int main (int argc, char **argv)
+{
+  checklang();
+
+  LIBMTP_Init();
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+  files = LIBMTP_Get_Filelisting_With_Callback (device, NULL, NULL);
+  folders = LIBMTP_Get_Folder_List (device);
+
+  if ((strncmp(basename(argv[0]),"mtp-delfile",11) == 0) || (strncmp(basename(argv[0]),"delfile",7) == 0)) {
+    delfile_command(argc,argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-getfile",13) == 0) || (strncmp(basename(argv[0]),"getfile",9) == 0)) {
+    getfile_command(argc,argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-newfolder",13) == 0) || (strncmp(basename(argv[0]),"newfolder",9) == 0)) {
+    newfolder_command(argc,argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-sendfile",11) == 0) || (strncmp(basename(argv[0]),"sendfile",7) == 0)) {
+    sendfile_command(argc, argv);
+  } else if ((strncmp(basename(argv[0]),"mtp-sendtr",10) == 0) || (strncmp(basename(argv[0]),"sendtr",6) == 0)) {
+    sendtrack_command(argc, argv);
+  } else {  
+    if ( argc < 2 ) {
+      usage ();
+      return 1;
+    }
+
+    while (1) {
+      int option_index = 0;
+      static struct option long_options[] = {
+        {"delete", 1, 0, 'd'},
+        {"sendfile", 1, 0, 'f'},
+        {"getfile", 1, 0, 'g'},
+        {"newfolder", 1, 0, 'n'},
+        {"sendtrack", 1, 0, 't'},
+        {0, 0, 0, 0}
+      };
+  
+      int c = getopt_long (argc, argv, "d:f:g:n:t:", long_options, &option_index);
+      if (c == -1)
+        break;
+  
+      char *arg1, *arg2;
+      switch (c) {
+      case 'd':
+        printf("Delete %s\n",optarg);
+        delfile_function(optarg);
+        break;
+  
+      case 'f':
+        printf("Send file %s\n",optarg);
+        split_arg(optarg,&arg1,&arg2);
+        sendfile_function(arg1,arg2);
+        break;
+  
+      case 'g':
+        printf("Get file %s\n",optarg);
+        split_arg(optarg,&arg1,&arg2);
+        getfile_function(arg1,arg2);
+        break;
+  
+      case 'n':
+        printf("New folder %s\n",optarg);
+        newfolder_function(optarg);
+        break;
+  
+      case 't':
+        printf("Send track %s\n",optarg);
+        split_arg(optarg,&arg1,&arg2);
+        sendtrack_function(arg1,arg2,NULL,NULL,NULL,NULL,NULL,NULL,0,0,0);
+        break;
+      }
+    }
+  
+    if (optind < argc) {
+      printf("Unknown options: ");
+      while (optind < argc)
+        printf("%s ", argv[optind++]);
+      printf("\n");
+    }
+  }
+  
+  LIBMTP_Release_Device(device);
+
+  exit (0);
+}
+
diff --git a/examples/delfile.c b/examples/delfile.c
new file mode 100644
index 0000000..670c703
--- /dev/null
+++ b/examples/delfile.c
@@ -0,0 +1,113 @@
+/** 
+ * \file delfile.c
+ * Example program to delete a file off the device.
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include "string.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <limits.h>
+
+void delfile_usage(void);
+void delfile_function(char *);
+void delfile_command(int, char **);
+
+extern LIBMTP_mtpdevice_t *device;
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+
+void delfile_usage(void)
+{
+  printf("Usage: delfile [-n] <fileid/trackid> | -f <filename>\n");
+}
+
+void
+delfile_function(char * path)
+{
+  uint32_t id = parse_path (path,files,folders);
+
+  if (id > 0) {
+    printf("Deleting %s which has item_id:%d\n",path,id);
+    int ret = 1;
+    ret = LIBMTP_Delete_Object(device, id);
+    if (ret != 0) {
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+      printf("Failed to remove file\n");
+    }
+  }
+}
+
+void delfile_command(int argc, char **argv)
+{
+  int FILENAME = 1;
+  int ITEMID = 2;
+  int field_type = 0;
+  int i;
+
+  if ( argc > 2 ) {
+    if (strncmp(argv[1],"-f",2) == 0) {
+      field_type = FILENAME;
+      strcpy(argv[1],"");
+    } else if (strncmp(argv[1],"-n",2) == 0) {
+      field_type = ITEMID;
+      strcpy(argv[1],"0");
+    } else {
+      delfile_usage();
+      return;
+    }
+  } else {
+    delfile_usage();
+    return;
+  }
+
+  for (i=1;i<argc;i++) {
+    uint32_t id;
+    char *endptr;
+    int ret = 0;
+
+    if (field_type == ITEMID) {
+      // Sanity check song ID
+      id = strtoul(argv[i], &endptr, 10);
+      if ( *endptr != 0 ) {
+        fprintf(stderr, "illegal value %s .. skipping\n", argv[i]);
+        id = 0;
+      }
+    } else {
+      if (strlen(argv[i]) > 0) {
+        id = parse_path (argv[i],files,folders);
+      } else {
+        id = 0;
+      }
+    }
+    if (id > 0 ) {
+      printf("Deleting %s\n",argv[i]);
+      ret = LIBMTP_Delete_Object(device, id);
+    }
+    if ( ret != 0 ) {
+      printf("Failed to delete file:%s\n",argv[i]);
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+      ret = 1;
+    }
+  }
+}
+
diff --git a/examples/detect.c b/examples/detect.c
new file mode 100644
index 0000000..393fd2c
--- /dev/null
+++ b/examples/detect.c
@@ -0,0 +1,268 @@
+/** 
+ * \file detect.c
+ * Example program to detect a device and list capabilities.
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include "util.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#define XML_BUFSIZE 0x10000
+
+static void dump_xml_fragment(uint8_t *buf, uint32_t len)
+{
+  static int endianness = 0; // 0 = LE, 1 = BE
+  uint32_t bp = 0;
+  
+  while (bp < len) {
+    if (buf[bp+0] == 0xFF && buf[bp+1] == 0xFE) {
+      endianness = 0;
+    } else if (buf[bp+0] == 0xFE && buf[bp+1] == 0xff) {
+      endianness = 1;
+    } else {
+      uint16_t tmp;
+      
+      if (endianness == 0) {
+	tmp = buf[bp+1] << 8 | buf[bp+0];
+      } else {
+	tmp = buf[bp+0] << 8 | buf[bp+1];
+      }
+      // Fix this some day, we only print ISO 8859-1 correctly here,
+      // should atleast support UTF-8.
+      printf("%c", (uint8_t) tmp);
+    }
+    bp += 2;
+  }
+  printf("\n");
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_raw_device_t * rawdevices;
+  int numrawdevices;
+  LIBMTP_error_number_t err;
+  int i;
+
+  LIBMTP_Init();
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  fprintf(stdout, "Listing raw device(s)\n");
+  err = LIBMTP_Detect_Raw_Devices(&rawdevices, &numrawdevices);
+  switch(err) {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "   No raw devices found.\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "Detect: There has been an error connecting. Exiting\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "Detect: Encountered a Memory Allocation Error. Exiting\n");
+    return 1;
+  case LIBMTP_ERROR_NONE:
+    {
+      int i;
+      
+      fprintf(stdout, "   Found %d device(s):\n", numrawdevices);
+      for (i = 0; i < numrawdevices; i++) {
+	if (rawdevices[i].device_entry.vendor != NULL ||
+	    rawdevices[i].device_entry.product != NULL) {
+	  fprintf(stdout, "   %s: %s (%04x:%04x) @ bus %d, dev %d\n", 
+		  rawdevices[i].device_entry.vendor,
+		  rawdevices[i].device_entry.product,
+		  rawdevices[i].device_entry.vendor_id,
+		  rawdevices[i].device_entry.product_id,
+		  rawdevices[i].bus_location,
+		  rawdevices[i].devnum);
+	} else {
+	  fprintf(stdout, "   %04x:%04x @ bus %d, dev %d\n", 
+		  rawdevices[i].device_entry.vendor_id,
+		  rawdevices[i].device_entry.product_id,
+		  rawdevices[i].bus_location,
+		  rawdevices[i].devnum);
+	}
+      }
+    }
+    break;
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "Unknown connection error.\n");
+    return 1;
+  }
+
+  /* Iterate over connected MTP devices */
+  fprintf(stdout, "Attempting to connect device(s)\n");
+  for (i = 0; i < numrawdevices; i++) {
+    LIBMTP_mtpdevice_t *device;
+    LIBMTP_file_t *files;
+    char *friendlyname;
+    char *syncpartner;
+    char *sectime;
+    char *devcert;
+    uint16_t *filetypes;
+    uint16_t filetypes_len;
+    uint8_t maxbattlevel;
+    uint8_t currbattlevel;
+    int ret;
+
+    device = LIBMTP_Open_Raw_Device(&rawdevices[i]);
+    if (device == NULL) {
+      fprintf(stderr, "Unable to open raw device %d\n", i);
+      continue;
+    }
+
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+    LIBMTP_Dump_Device_Info(device);
+    
+    printf("MTP-specific device properties:\n");
+    // The friendly name
+    friendlyname = LIBMTP_Get_Friendlyname(device);
+    if (friendlyname == NULL) {
+      fprintf(stdout, "   Friendly name: (NULL)\n");
+    } else {
+      fprintf(stdout, "   Friendly name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+    syncpartner = LIBMTP_Get_Syncpartner(device);
+    if (syncpartner == NULL) {
+      fprintf(stdout, "   Synchronization partner: (NULL)\n");
+    } else {
+      fprintf(stdout, "   Synchronization partner: %s\n", syncpartner);
+      free(syncpartner);
+    }
+    
+    // Some battery info
+    ret = LIBMTP_Get_Batterylevel(device, &maxbattlevel, &currbattlevel);
+    if (ret == 0) {
+      fprintf(stdout, "   Battery level %d of %d (%d%%)\n",currbattlevel, maxbattlevel, 
+	      (int) ((float) currbattlevel/ (float) maxbattlevel * 100.0));
+    } else {
+      // Silently ignore. Some devices does not support getting the 
+      // battery level.
+      LIBMTP_Clear_Errorstack(device);
+    }
+    
+    ret = LIBMTP_Get_Supported_Filetypes(device, &filetypes, &filetypes_len);
+    if (ret == 0) {
+      uint16_t i;
+      
+      printf("libmtp supported (playable) filetypes:\n");
+      for (i = 0; i < filetypes_len; i++) {
+	fprintf(stdout, "   %s\n", LIBMTP_Get_Filetype_Description(filetypes[i]));
+      }
+    } else {
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+    
+    // Secure time XML fragment
+    ret = LIBMTP_Get_Secure_Time(device, &sectime);
+    if (ret == 0 && sectime != NULL) {
+      fprintf(stdout, "\nSecure Time:\n%s\n", sectime);
+      free(sectime);
+    } else {
+      // Silently ignore - there may be devices not supporting secure time.
+      LIBMTP_Clear_Errorstack(device);
+    }
+    
+    // Device certificate XML fragment
+    ret = LIBMTP_Get_Device_Certificate(device, &devcert);
+    if (ret == 0 && devcert != NULL) {
+      fprintf(stdout, "\nDevice Certificate:\n%s\n", devcert);
+      free(devcert);
+    } else {
+      fprintf(stdout, "Unable to acquire device certificate, perhaps this device "
+	      "does not support this\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+
+    // Try to get Media player device info XML file...
+    files = LIBMTP_Get_Filelisting_With_Callback(device, NULL, NULL);
+    if (files != NULL) {
+      LIBMTP_file_t *file, *tmp;
+      file = files;
+      while (file != NULL) {
+	if (!strcmp(file->filename, "WMPInfo.xml") ||
+	    !strcmp(file->filename, "WMPinfo.xml") ||
+	    !strcmp(file->filename, "default-capabilities.xml")) {
+	    if (file->item_id != 0) {
+	      /* Dump this file */
+	      FILE *xmltmp = tmpfile();
+	      int tmpfiledescriptor = fileno(xmltmp);
+	      
+	      if (tmpfiledescriptor != -1) {
+		int ret = LIBMTP_Get_Track_To_File_Descriptor(device,
+							      file->item_id,
+							      tmpfiledescriptor,
+							      NULL,
+							      NULL);
+		if (ret == 0) {
+		  uint8_t *buf = NULL;
+		  uint32_t readbytes;
+		  
+		  buf = malloc(XML_BUFSIZE);
+		  if (buf == NULL) {
+		    printf("Could not allocate %08x bytes...\n", XML_BUFSIZE);
+		    LIBMTP_Dump_Errorstack(device);
+		    LIBMTP_Clear_Errorstack(device);
+		    free(rawdevices);
+		    return 1;
+		  }
+		  
+		  lseek(tmpfiledescriptor, 0, SEEK_SET);
+		  readbytes = read(tmpfiledescriptor, (void*) buf, XML_BUFSIZE);
+		  
+		  if (readbytes >= 2 && readbytes < XML_BUFSIZE) {
+		    fprintf(stdout, "\n%s file contents:\n", file->filename);
+		    dump_xml_fragment(buf, readbytes);
+		  } else {
+		    perror("Unable to read file");
+		    LIBMTP_Dump_Errorstack(device);
+		    LIBMTP_Clear_Errorstack(device);
+		  }
+		  free(buf);
+		} else {
+		  LIBMTP_Dump_Errorstack(device);
+		  LIBMTP_Clear_Errorstack(device);
+		}
+		fclose(xmltmp);
+	      }
+	    }
+	}
+	tmp = file;
+	file = file->next;
+	LIBMTP_destroy_file_t(tmp);
+      }
+    }
+    LIBMTP_Release_Device(device);
+  } /* End For Loop */
+
+  free(rawdevices);
+
+  printf("OK.\n");
+  
+  return 0; 
+}
diff --git a/examples/emptyfolders.c b/examples/emptyfolders.c
new file mode 100644
index 0000000..9cd7b49
--- /dev/null
+++ b/examples/emptyfolders.c
@@ -0,0 +1,112 @@
+/** 
+ * \file emptyfolders.c
+ * Example program that prunes empty folders.
+ *
+ * Copyright (C) 2006 Andy Kelk <andy@mopoke.co.uk>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+
+static void prune_empty_folders(LIBMTP_mtpdevice_t *device, LIBMTP_file_t *files, LIBMTP_folder_t *folderlist, int do_delete)
+{
+  if(folderlist==NULL)
+    return;
+
+  if(folderlist->child == NULL) { // this *might* be empty
+    // therefore, check every file for this parent_id
+    int found = 0;
+    LIBMTP_file_t *file;
+    file = files;
+    while (file != NULL) {
+      if(file->parent_id == folderlist->folder_id) { // folder has a child
+        found = 1;
+        break;
+      }
+      file = file->next;
+    }
+
+    if(found == 0) { // no files claim this as a parent
+      printf("empty folder %u (%s)\n",folderlist->folder_id,folderlist->name);
+      if(do_delete) {
+        if (LIBMTP_Delete_Object(device,folderlist->folder_id) != 0) {
+          printf("Couldn't delete folder %u\n",folderlist->folder_id);
+	  LIBMTP_Dump_Errorstack(device);
+	  LIBMTP_Clear_Errorstack(device);
+        }
+      }
+    }
+  }
+
+  prune_empty_folders(device,files,folderlist->child,do_delete); // recurse down
+  prune_empty_folders(device,files,folderlist->sibling,do_delete); // recurse along
+}
+
+int main (int argc, char **argv)
+{
+  // check if we're doing a dummy run
+  int do_delete = 0;
+  int opt;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "d")) != -1 ) {
+    switch (opt) {
+    case 'd':
+      do_delete = 1;
+      break;
+    default:
+      break;
+    }
+  }
+
+  if(do_delete == 0) {
+    printf("This is a dummy run. No folders will be deleted.\n");
+    printf("To delete folders, use the '-d' option.\n");
+  }
+
+  LIBMTP_mtpdevice_t *device;
+  LIBMTP_folder_t *folders;
+  LIBMTP_file_t *files;
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    exit (0);
+  }
+
+  // Get file listing.
+  files = LIBMTP_Get_Filelisting_With_Callback(device,NULL,NULL);
+
+  // Get folder listing.
+  folders = LIBMTP_Get_Folder_List(device);
+
+  if(folders == NULL) {
+    printf("No folders found\n");
+  } else {
+    prune_empty_folders(device,files,folders,do_delete);
+  }
+
+  LIBMTP_destroy_folder_t(folders);
+  LIBMTP_destroy_file_t(files);
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/evolution-sync.sh b/examples/evolution-sync.sh
new file mode 100755
index 0000000..53ca0b9
--- /dev/null
+++ b/examples/evolution-sync.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+
+# Example evolution synchronization script by Nicolas Tetreault,
+# modified by Linus Walleij.
+
+# Define target files
+SYNC_HOME=$HOME/MTP_device_sync
+
+# Define tool locations
+SENDFILE=`which mtp-sendfile`
+# SENDFILE="$HOME/comp-apps/bin/sendfile"
+#EADDEXP=`which evolution-addressbook-export`
+# This is the location in Fedora Core 5:
+EADDEXP="/usr/libexec/evolution/2.6/evolution-addressbook-export"
+
+# You need to change the name of the files
+# that contains the calendar and contacts on your device. 
+# You can find out by  starting Gnomad2, choose the data transfer 
+# tab, sort by size (it should be small files, extension .ics and .vcf)
+# On my Zen Microphoto, the calendar and contacts files are called
+# 6651416 with the ics and vcf extensions, respectively.
+CALENDAR_FILE="6651416.ics"
+CONTACTS_FILE="6651416.vcf"
+
+# The evolution address book. To list your addressbooks, type:
+# evolution-addressbook-export -l
+# the output for me:
+# "file:///home/nt271/.evolution/addressbook/local/system
+# ","Personal",26
+# "file:///home/nt271/.evolution/addressbook/local/1158600180.5386.0@sierra"
+# ,"MicroPhoto",24
+# I only want the Microphoto addressbook and the output will be
+# $SYNC_HOME/contacts/Evolution_contacts.vcf
+EVOLUTION_CONTACTS="file:///home/linus/.evolution/addressbook/local/system"
+
+# Check for sync dir, create it if needed
+
+if test -d $SYNC_HOME ; then
+    echo "$SYNC_HOME exists, OK."
+else
+    echo "$SYNC_HOME must first be created..."
+    mkdir $SYNC_HOME
+    # This is a working dir for contact merging, you can put
+    # in some extra .vcf files here as well if you like.
+    mkdir $SYNC_HOME/contacts
+    # Here you can place some extra calendars to be sync:ed, you
+    # can put in some extra .ics files of any kind here.
+    mkdir $SYNC_HOME/calendars
+fi
+
+# Check for prerequisites
+
+if test -f $EADDEXP ; then
+    echo "evolution-addressbook-export present in $EADDEXP, OK."
+else
+    echo "Cannot locate evolution-addressbook-export!!"
+    exit 0
+fi
+
+
+# Next line merges all of your tasklist, your personal calendar, 
+# and then any saved to disk calendar you have placed in
+# $SYNC_HOME/calendars
+
+cat $HOME/.evolution/tasks/local/system/tasks.ics \
+    $HOME/.evolution/calendar/local/system/calendar.ics \
+    $SYNC_HOME/calendars/*.ics > $SYNC_HOME/$CALENDAR_FILE
+
+# Use evolution-addressbook-export (installed with Evolution) to
+# export your contacts to vcard.
+
+$EADDEXP --format=vcard \
+    --output=$SYNC_HOME/contacts/Evolution_contacts.vcf \
+    $EVOLUTION_CONTACTS
+
+# Repeat for each addressbook you want to upload.
+
+# The next command will then merge all the contact lists
+
+cat $SYNC_HOME/contacts/*.vcf > $SYNC_HOME/$CONTACTS_FILE
+
+# The calendar and contacts files now need to be converted from unix
+# to DOS linefeeds (CR+LF instead of just LF)
+
+unix2dos $SYNC_HOME/$CALENDAR_FILE $SYNC_HOME/$CONTACTS_FILE
+
+# You can now upload the ics and vcf files to you My Organizer folder
+# on your device. Change the path to your sendfile command.
+# Sending the vcf file is only supported in CVS version at this time
+
+$SENDFILE -f "My Organizer" -t ics $SYNC_HOME/$CALENDAR_FILE
+$SENDFILE -f "My Organizer" -t vcf $SYNC_HOME/$CONTACTS_FILE
+
diff --git a/examples/files.c b/examples/files.c
new file mode 100644
index 0000000..9ccf3d7
--- /dev/null
+++ b/examples/files.c
@@ -0,0 +1,120 @@
+/** 
+ * \file files.c
+ * Example program that lists all files on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+
+static void dump_fileinfo(LIBMTP_file_t *file)
+{
+  printf("File ID: %u\n", file->item_id);
+  if (file->filename != NULL)
+    printf("   Filename: %s\n", file->filename);
+
+  // This is sort of special...
+  if (file->filesize == (uint32_t) -1) {
+    printf("   None. (abstract file, size = -1)\n");
+  } else {
+#ifdef __WIN32__
+    printf("   File size %llu (0x%016I64X) bytes\n", file->filesize, file->filesize);
+#else
+    printf("   File size %llu (0x%016llX) bytes\n",
+	   (long long unsigned int) file->filesize, 
+	   (long long unsigned int) file->filesize);
+#endif
+  }
+  printf("   Parent ID: %u\n", file->parent_id);
+  printf("   Storage ID: 0x%08X\n", file->storage_id);
+  printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(file->filetype));
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device_list, *iter;
+  LIBMTP_file_t *files;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+
+  switch(LIBMTP_Get_Connected_Devices(&device_list))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-files: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-files: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-files: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-files: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-files: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device_list; iter != NULL; iter = iter->next)
+  {
+  	
+    char *friendlyname;
+    
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Listing File Information on Device with name: (NULL)\n");
+    } else {
+      printf("Listing File Information on Device with name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+  
+	  /* Get track listing. */
+	  files = LIBMTP_Get_Filelisting_With_Callback(iter, NULL, NULL);
+	  if (files == NULL) {
+	    printf("No files.\n");
+	    LIBMTP_Dump_Errorstack(iter);
+	    LIBMTP_Clear_Errorstack(iter);
+	  } else {
+	    LIBMTP_file_t *file, *tmp;
+	    file = files;
+	    while (file != NULL) {
+	      dump_fileinfo(file);
+	      tmp = file;
+	      file = file->next;
+	      LIBMTP_destroy_file_t(tmp);
+      }
+	  }
+  }
+    
+  LIBMTP_Release_Device_List(device_list);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/folders.c b/examples/folders.c
new file mode 100644
index 0000000..ee63709
--- /dev/null
+++ b/examples/folders.c
@@ -0,0 +1,109 @@
+/** 
+ * \file folders.c
+ * Example program that lists all folders on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+
+static void dump_folder_list(LIBMTP_folder_t *folderlist, int level)
+{
+  int i;
+  if(folderlist==NULL) {
+    return;
+  }
+
+  printf("%u\t", folderlist->folder_id);
+  for(i=0;i<level;i++) printf("  ");
+
+  printf("%s\n", folderlist->name);
+
+  dump_folder_list(folderlist->child, level+1);
+  dump_folder_list(folderlist->sibling, level);
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device, *iter;
+  LIBMTP_folder_t *folders;
+
+  LIBMTP_Init();
+  fprintf(stdout, "Attempting to connect device(s)\n");
+
+  switch(LIBMTP_Get_Connected_Devices(&device))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-folders: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-folders: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-folders: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-folders: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-folders: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device; iter != NULL; iter = iter->next)
+  {
+  	char *friendlyname;
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Friendly name: (NULL)\n");
+    } else {
+      printf("Friendly name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+    
+    LIBMTP_Dump_Errorstack(iter);
+    LIBMTP_Clear_Errorstack(iter);    /* Get folder listing */
+
+    folders = LIBMTP_Get_Folder_List(iter);
+    
+    if (folders == NULL) {
+      fprintf(stdout, "No folders found\n");
+      LIBMTP_Dump_Errorstack(iter);
+      LIBMTP_Clear_Errorstack(iter);
+    } else {
+      dump_folder_list(folders,0);
+    }
+
+    LIBMTP_destroy_folder_t(folders);
+  }
+
+  
+  LIBMTP_Release_Device_List(device);
+  printf("OK.\n");
+
+  return 0;
+}
diff --git a/examples/format.c b/examples/format.c
new file mode 100644
index 0000000..52608a9
--- /dev/null
+++ b/examples/format.c
@@ -0,0 +1,86 @@
+/** 
+ * \file format.c
+ * Example program that formats the device storage.
+ *
+ * Copyright (C) 2006-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+
+/**
+ * Returns 0 if OK (yes), 1 if not OK (no)
+ */
+static int prompt()
+{
+  char buff[2];
+  
+  while (1) {
+    fprintf(stdout, "> ");
+    if ( fgets(buff, sizeof(buff), stdin) == NULL ) {
+      if (ferror(stdin)) {
+        fprintf(stderr, "File error on stdin\n");
+      } else {
+        fprintf(stderr, "EOF on stdin\n");
+      }
+      return 1;
+    }
+    if (buff[0] == 'y') {
+      return 0;
+    } else if (buff[0] == 'n') {
+      return 1;
+    }
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  int ret;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  printf("I will now format your device. This means that\n");
+  printf("all content (and licenses) will be lost forever.\n");
+  printf("you will not be able to undo this operation.\n");
+  printf("Continue? (y/n)\n");
+  if (prompt() == 0) {
+    // This will just format the first storage.
+    ret = LIBMTP_Format_Storage(device, device->storage);
+  } else {
+    printf("Aborted.\n");
+    ret = 0;
+  }
+
+  if ( ret != 0 ) {
+    printf("Failed to format device.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+    LIBMTP_Release_Device(device);
+    return 1;
+  }
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
diff --git a/examples/getfile.c b/examples/getfile.c
new file mode 100644
index 0000000..7df2453
--- /dev/null
+++ b/examples/getfile.c
@@ -0,0 +1,91 @@
+/** 
+ * \file getfile.c
+ * Example program to retrieve a file off the device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <limits.h>
+
+void getfile_function(char *,char *);
+void getfile_command(int, char **);
+void getfile_usage(void);
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+void getfile_usage (void)
+{
+  fprintf(stderr, "getfile <fileid/trackid> <filename>\n");
+}
+
+void
+getfile_function(char * from_path,char * to_path)
+{
+  int id = parse_path (from_path,files,folders);
+  if (id > 0) {
+    printf("Getting %s to %s\n",from_path,to_path);
+    if (LIBMTP_Get_File_To_File(device, id, to_path, progress, NULL) != 0 ) {
+      printf("\nError getting file from MTP device.\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+  }
+}
+
+
+void getfile_command(int argc, char **argv)
+{
+  uint32_t id;
+  char *endptr;
+  char *file;
+
+  // We need file ID and filename
+  if ( argc != 3 ) {
+    getfile_usage();
+    return;
+  }
+
+  // Sanity check song ID
+  id = strtoul(argv[1], &endptr, 10);
+  if ( *endptr != 0 ) {
+    fprintf(stderr, "illegal value %s\n", argv[1]);
+    return;
+  } else if ( ! id ) {
+    fprintf(stderr, "bad file/track id %u\n", id);
+    return;
+ }
+
+  // Filename, e.g. "foo.mp3"
+  file = argv[2];
+  printf("Getting file/track %d to local file %s\n", id, file);
+
+  // This function will also work just as well for tracks.
+  if (LIBMTP_Get_File_To_File(device, id, file, progress, NULL) != 0 ) {
+    printf("\nError getting file from MTP device.\n");
+  }
+  // Terminate progress bar.
+  printf("\n");
+  
+  return;
+}
+
diff --git a/examples/getplaylist.c b/examples/getplaylist.c
new file mode 100644
index 0000000..cc9c4ca
--- /dev/null
+++ b/examples/getplaylist.c
@@ -0,0 +1,93 @@
+/** 
+ * \file getplaylist.c
+ * Example program that lists the abstract playlists on the device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+#include <limits.h>
+
+static uint32_t dump_playlist(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
+{
+  uint32_t i;
+
+  printf("Number of items: %u\n", pl->no_tracks);
+  if(pl->no_tracks > 0) {
+    for(i=0;i<pl->no_tracks;i++) {
+      LIBMTP_track_t *track;
+      
+      track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
+      if (track != NULL) {
+	printf("   %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
+	LIBMTP_destroy_track_t(track);
+      } else {
+	printf("   %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
+	LIBMTP_Dump_Errorstack(device);
+	LIBMTP_Clear_Errorstack(device);
+      }
+    }
+  }
+  return 0;
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  LIBMTP_playlist_t *playlist;
+  uint32_t id;
+  char *endptr;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  // We need file ID
+  if ( argc != 2 ) {
+    fprintf(stderr, "Just a playlist ID is required\n");
+    return 1;
+  }
+
+  // Sanity check playlist ID
+  id = strtoul(argv[1], &endptr, 10);
+  if ( *endptr != 0 ) {
+    fprintf(stderr, "illegal value %s\n", argv[1]);
+    return 1;
+  } else if ( ! id ) {
+    fprintf(stderr, "bad playlist id %u\n", id);
+    return 1;
+ }
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices. Connect/replug device and try again.\n");
+    exit (0);
+  }
+
+  playlist = LIBMTP_Get_Playlist(device,id);  
+
+  if (playlist != NULL) {
+    dump_playlist(device,playlist);
+  }
+
+  LIBMTP_destroy_playlist_t(playlist);
+  
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/hotplug.c b/examples/hotplug.c
new file mode 100644
index 0000000..c2f36c4
--- /dev/null
+++ b/examples/hotplug.c
@@ -0,0 +1,213 @@
+/** 
+ * \file hotplug.c
+ * Example program to create hotplug scripts.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006-2008 Marcus Meissner <marcus@jet.franken.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+static void usage(void)
+{
+  fprintf(stderr, "usage: hotplug [-u -H -i -a\"ACTION\"]\n");
+  fprintf(stderr, "       -u:  use udev syntax\n");
+  fprintf(stderr, "       -H:  use hal syntax\n");
+  fprintf(stderr, "       -i:  use usb.ids simple list syntax\n");
+  fprintf(stderr, "       -a\"ACTION\": perform udev action ACTION on attachment\n");
+  exit(1);
+}
+
+enum style {
+  style_usbmap,
+  style_udev,
+  style_hal,
+  style_usbids
+};
+
+int main (int argc, char **argv)
+{
+  LIBMTP_device_entry_t *entries;
+  int numentries;
+  int i;
+  int ret;
+  enum style style = style_usbmap;
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  char *udev_action = NULL;
+  char default_udev_action[] = "SYMLINK+=\"libmtp-%k\", MODE=\"666\"";
+  char *action; // To hold the action actually used.
+  uint16_t last_vendor = 0x0000U;  
+
+  while ( (opt = getopt(argc, argv, "uUiHa:")) != -1 ) {
+    switch (opt) {
+    case 'a':
+      udev_action = strdup(optarg);
+    case 'u':
+      style = style_udev;
+      break;
+    case 'H':
+      style = style_hal;
+      break;
+    case 'i':
+      style = style_usbids;
+      break;
+    default:
+      usage();
+    }
+  }
+
+  if (udev_action != NULL) {
+    action = udev_action;
+  } else {
+    action = default_udev_action;
+  }
+
+  LIBMTP_Init();
+  ret = LIBMTP_Get_Supported_Devices_List(&entries, &numentries);
+  if (ret == 0) {
+    switch (style) {
+    case style_udev:
+      printf("# UDEV-style hotplug map for libmtp\n");
+      printf("# Put this file in /etc/udev/rules.d\n\n");
+      printf("ACTION!=\"add\", GOTO=\"libmtp_rules_end\"\n");
+      printf("ENV{MAJOR}!=\"?*\", GOTO=\"libmtp_rules_end\"\n");
+      printf("SUBSYSTEM==\"usb\", GOTO=\"libmtp_usb_rules\"\n"
+	     "# The following thing will be deprecated when older kernels are phased out.\n"
+             "SUBSYSTEM==\"usb_device\", GOTO=\"libmtp_usb_device_rules\"\n"
+	     "GOTO=\"libmtp_rules_end\"\n\n"
+	     "LABEL=\"libmtp_usb_rules\"\n\n");
+      break;
+    case style_usbmap:
+      printf("# This usermap will call the script \"libmtp.sh\" whenever a known MTP device is attached.\n\n");
+      break;
+    case style_hal:
+      printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?> <!-- -*- SGML -*- -->\n");
+      printf("<!-- This file was generated by %s - - fdi -->\n", argv[0]);
+      printf("<deviceinfo version=\"0.2\">\n");
+      printf("  <device>\n");
+      printf("    <match key=\"info.subsystem\" string=\"usb\">\n");
+      break;
+    case style_usbids:
+      printf("# usb.ids style device list from libmtp\n");
+      printf("# Compare: http://www.linux-usb.org/usb.ids\n");
+      break;
+    }
+
+    for (i = 0; i < numentries; i++) {
+      LIBMTP_device_entry_t * entry = &entries[i];
+
+      switch (style) {
+      case style_udev: 
+	{
+          printf("# %s %s\n", entry->vendor, entry->product);
+	  // Old style directly SYSFS named.
+	  // printf("SYSFS{idVendor}==\"%04x\", SYSFS{idProduct}==\"%04x\", %s\n", entry->vendor_id, entry->product_id, action);
+	  // Newer style
+	  printf("ATTR{idVendor}==\"%04x\", ATTR{idProduct}==\"%04x\", %s\n", entry->vendor_id, entry->product_id, action);
+	  break;
+        }
+      case style_usbmap:
+          printf("# %s %s\n", entry->vendor, entry->product);
+          printf("libmtp.sh    0x0003  0x%04x  0x%04x  0x0000  0x0000  0x00    0x00    0x00    0x00    0x00    0x00    0x00000000\n", entry->vendor_id, entry->product_id);
+          break;
+        case style_hal:
+          printf("      <!-- %s %s -->\n", entry->vendor, entry->product);
+          printf("      <match key=\"usb.vendor_id\" int=\"0x%04x\">\n", entry->vendor_id);
+          printf("        <match key=\"usb.product_id\" int=\"0x%04x\">\n", entry->product_id);
+          /* FIXME: If hal >=0.5.10 can be depended upon, the matches below with contains_not can instead use addset */
+          printf("          <match key=\"info.capabilities\" contains_not=\"portable_audio_player\">\n");
+          printf("            <append key=\"info.capabilities\" type=\"strlist\">portable_audio_player</append>\n");
+          printf("          </match>\n");
+          printf("          <merge key=\"info.vendor\" type=\"string\">%s</merge>\n", entry->vendor);
+          printf("          <merge key=\"info.product\" type=\"string\">%s</merge>\n", entry->product);
+          printf("          <merge key=\"info.category\" type=\"string\">portable_audio_player</merge>\n");
+          printf("          <merge key=\"portable_audio_player.access_method\" type=\"string\">user</merge>\n");
+          printf("          <match key=\"portable_audio_player.access_method.protocols\" contains_not=\"mtp\">\n");
+          printf("            <append key=\"portable_audio_player.access_method.protocols\" type=\"strlist\">mtp</append>\n");
+          printf("          </match>\n");
+          printf("          <append key=\"portable_audio_player.access_method.drivers\" type=\"strlist\">libmtp</append>\n");
+          /* FIXME: needs true list of formats ... But all of them can do MP3 and WMA */
+          printf("          <match key=\"portable_audio_player.output_formats\" contains_not=\"audio/mpeg\">\n");
+          printf("            <append key=\"portable_audio_player.output_formats\" type=\"strlist\">audio/mpeg</append>\n");
+          printf("          </match>\n");
+          printf("          <match key=\"portable_audio_player.output_formats\" contains_not=\"audio/x-ms-wma\">\n");
+          printf("            <append key=\"portable_audio_player.output_formats\" type=\"strlist\">audio/x-ms-wma</append>\n");
+          printf("          </match>\n");
+	  /* Special hack to support the OGG format - irivers, TrekStor and NormSoft (Palm) can always play these files! */
+	  if (entry->vendor_id == 0x4102 || // iriver
+	      entry->vendor_id == 0x066f || // TrekStor
+	      entry->vendor_id == 0x1703) { // NormSoft, Inc.
+	    printf("          <match key=\"portable_audio_player.output_formats\" contains_not=\"application/ogg\">\n");
+	    printf("            <append key=\"portable_audio_player.output_formats\" type=\"strlist\">application/ogg</append>\n");
+	    printf("          </match>\n");
+	  }
+          printf("          <merge key=\"portable_audio_player.libmtp.protocol\" type=\"string\">mtp</merge>\n");
+          printf("        </match>\n");
+          printf("      </match>\n");
+        break;
+        case style_usbids:
+          if (last_vendor != entry->vendor_id) {
+            printf("%04x\n", entry->vendor_id);
+          }
+          printf("\t%04x  %s %s\n", entry->product_id, entry->vendor, entry->product);
+        break;
+      }
+      last_vendor = entry->vendor_id;
+    }
+  } else {
+    printf("Error.\n");
+    exit(1);
+  }
+
+  // For backward comparibility with the #$!+@! ever changing
+  // udev rule style...
+  if (style == style_udev) {
+    printf("GOTO=\"libmtp_rules_end\"\n\n");
+    printf("LABEL=\"libmtp_usb_device_rules\"\n");
+    for (i = 0; i < numentries; i++) {
+      LIBMTP_device_entry_t * entry = &entries[i];
+
+      printf("# %s %s\n", entry->vendor, entry->product);
+      printf("ATTRS{idVendor}==\"%04x\", ATTRS{idProduct}==\"%04x\", %s\n", entry->vendor_id, entry->product_id, action); 
+    }
+    printf("GOTO=\"libmtp_rules_end\"\n\n");
+  }
+
+  // Then the footer.
+  switch (style) {
+  case style_usbmap:
+    break;
+  case style_udev:
+    printf("LABEL=\"libmtp_rules_end\"\n");
+    break;
+  case style_hal:
+    printf("    </match>\n");
+    printf("  </device>\n");
+    printf("</deviceinfo>\n");
+    break;
+  case style_usbids:
+    printf("\n");
+  }
+
+  exit (0);
+}
diff --git a/examples/newfolder.c b/examples/newfolder.c
new file mode 100644
index 0000000..884c2bc
--- /dev/null
+++ b/examples/newfolder.c
@@ -0,0 +1,70 @@
+/** 
+ * \file newfolder.c
+ * Example program to create a folder on the device.
+ *
+ * Copyright (C) 2006-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <libgen.h>
+
+void newfolder_function(char *);
+void newfolder_command(int,char **);
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+void newfolder_command (int argc, char **argv)
+{
+  uint32_t newid;
+  
+  if(argc != 4) {
+    printf("Usage: newfolder name <parent> <storage>\n");
+    printf("  parent = parent folder or 0 to create the new folder in the root dir\n");
+    printf("  storage = storage id or 0 to create the new folder on the primary storage\n");
+    return;
+  }
+  
+  newid = LIBMTP_Create_Folder(device, argv[1], atol(argv[2]), atol(argv[3]));
+  if (newid == 0) {
+    printf("Folder creation failed.\n");
+  } else {
+    printf("New folder created with ID: %d\n", newid);
+  }
+}
+
+void
+newfolder_function(char * path)
+{
+  printf("Creating new folder %s\n",path);
+  char * parent = dirname(path);
+  char * folder = basename(path);
+  int id = parse_path (parent,files,folders);
+  int newid = LIBMTP_Create_Folder(device, folder, id, 0);
+  if (newid == 0) {
+    printf("Folder creation failed.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  } else {
+    printf("New folder created with ID: %d\n", newid);
+  }
+}
+
diff --git a/examples/newplaylist.c b/examples/newplaylist.c
new file mode 100644
index 0000000..a5caf86
--- /dev/null
+++ b/examples/newplaylist.c
@@ -0,0 +1,109 @@
+/** 
+ * \file newplaylist.c
+ * Example program to create a playlist on a device.
+ *
+ * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include "string.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static void usage(void) {
+  printf("Usage: newplaylist -i <fileid/trackid> -n <playlistname>\n");
+  exit(0);
+}
+
+int main (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  LIBMTP_mtpdevice_t *device = NULL;
+  int idcount = 0;
+  uint32_t *ids = NULL;
+  uint32_t *tmp = NULL;
+  char *playlistname = NULL;
+  char *rest;
+ 
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "hn:i:")) != -1 ) {
+    switch (opt) {
+    case 'h':
+      usage();
+    case 'i':
+      idcount++;
+      if ((tmp = realloc(ids, sizeof(uint32_t) * (idcount))) == NULL) {
+        printf("realloc failed\n");
+        return 1;
+      }
+      ids = tmp;
+      ids[(idcount-1)] = strtoul(optarg, &rest, 0);
+      break;
+    case 'n':
+      playlistname = strdup(optarg);
+      break;
+    default:
+      usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+
+  if ( playlistname == NULL) {
+    printf("You need to supply a playlist name.\n");
+    usage();
+  }
+
+  if (idcount == 0) {
+    printf("You need to supply one or more track IDs\n");
+    usage();
+  }
+
+    
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  LIBMTP_playlist_t *playlist = LIBMTP_new_playlist_t();
+  playlist->name = playlistname;
+  playlist->no_tracks = idcount;
+  playlist->tracks = ids;
+  playlist->parent_id = 0;
+  playlist->storage_id = 0;
+  int ret = LIBMTP_Create_New_Playlist(device,playlist);
+  if (ret != 0) {
+    printf("Couldn't create playlist object\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  }
+  else {
+    printf("Created new playlist: %u\n", playlist->playlist_id);
+  }
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
+
diff --git a/examples/pathutils.c b/examples/pathutils.c
new file mode 100644
index 0000000..419a543
--- /dev/null
+++ b/examples/pathutils.c
@@ -0,0 +1,238 @@
+/** 
+ * \file pathutils.c
+ *
+ * Copyright (C) 2005-2008 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include "pathutils.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include <libgen.h>
+
+/* Find the folder_id of a given path
+ * Runs by walking through folders structure */
+static uint32_t
+lookup_folder_id (LIBMTP_folder_t * folder, char * path, char * parent)
+{
+  char * current;
+  uint32_t ret = (uint32_t) -1;
+
+  if (strcmp(path,"/")==0)
+    return 0;
+
+  if (folder == NULL) {
+    return ret;
+  }
+
+  current = malloc (strlen(parent) + strlen(folder->name) + 2);
+  sprintf(current,"%s/%s",parent,folder->name);
+  if (strcasecmp (path, current) == 0) {
+    free (current);
+    return folder->folder_id;
+  }
+  if (strncasecmp (path, current, strlen (current)) == 0) {
+    ret = lookup_folder_id (folder->child, path, current);
+  }
+  free (current);
+  if (ret != (uint32_t) (-1)) {
+    return ret;
+  }
+  ret = lookup_folder_id (folder->sibling, path, parent);
+  return ret;
+}
+
+/* Parses a string to find item_id */
+int
+parse_path (char * path, LIBMTP_file_t * files, LIBMTP_folder_t * folders)
+{
+  char *rest;
+  uint32_t item_id;
+
+  // Check if path is an item_id
+  if (*path != '/') {
+    item_id = strtoul(path, &rest, 0);
+    // really should check contents of "rest" here...
+    /* if not number, assume a file name */
+    if (item_id == 0) {
+      LIBMTP_file_t * file = files;
+
+      /* search for matching name */
+      while (file != NULL) {
+	if (strcasecmp (file->filename, path) == 0) {
+	  return file->item_id;
+	}
+	file = file->next;
+      }
+    }
+    return item_id;
+  }
+  // Check if path is a folder
+  item_id = lookup_folder_id(folders,path,"");
+  if (item_id == (uint32_t) -1) {
+    char * dirc = strdup(path);
+    char * basec = strdup(path);
+    char * parent = dirname(dirc);
+    char * filename = basename(basec);
+    uint32_t parent_id = lookup_folder_id(folders,parent,"");
+    LIBMTP_file_t * file;
+
+    file = files;
+    while (file != NULL) {
+      if (file->parent_id == parent_id) {
+        if (strcasecmp (file->filename, filename) == 0) {
+	  free(dirc);
+	  free(basec);
+          return file->item_id;
+        }
+      }
+      file = file->next;
+    }
+    free(dirc);
+    free(basec);
+  } else {
+    return item_id;
+  }
+
+  return -1;
+}
+
+int progress (const uint64_t sent, const uint64_t total, void const * const data)
+{
+  int percent = (sent*100)/total;
+#ifdef __WIN32__
+  printf("Progress: %I64u of %I64u (%d%%)\r", sent, total, percent);
+#else
+  printf("Progress: %llu of %llu (%d%%)\r", sent, total, percent);
+#endif
+  fflush(stdout);
+  return 0;
+}
+
+/* Find the file type based on extension */
+LIBMTP_filetype_t
+find_filetype (const char * filename)
+{
+  char *ptype;
+  LIBMTP_filetype_t filetype;
+
+#ifdef __WIN32__
+  ptype = strrchr(filename, '.');
+#else
+  ptype = rindex(filename,'.');
+#endif
+  // This accounts for the case with a filename without any "." (period).
+  if (!ptype) {
+    ptype = "";
+  } else {
+    ++ptype;
+  }
+
+  /* This need to be kept constantly updated as new file types arrive. */
+  if (!strcasecmp (ptype, "wav")) {
+    filetype = LIBMTP_FILETYPE_WAV;
+  } else if (!strcasecmp (ptype, "mp3")) {
+    filetype = LIBMTP_FILETYPE_MP3;
+  } else if (!strcasecmp (ptype, "wma")) {
+    filetype = LIBMTP_FILETYPE_WMA;
+  } else if (!strcasecmp (ptype, "ogg")) {
+    filetype = LIBMTP_FILETYPE_OGG;
+  } else if (!strcasecmp (ptype, "mp4")) {
+    filetype = LIBMTP_FILETYPE_MP4;
+  } else if (!strcasecmp (ptype, "wmv")) {
+    filetype = LIBMTP_FILETYPE_WMV;
+  } else if (!strcasecmp (ptype, "avi")) {
+    filetype = LIBMTP_FILETYPE_AVI;
+  } else if (!strcasecmp (ptype, "mpeg") || !strcasecmp (ptype, "mpg")) {
+    filetype = LIBMTP_FILETYPE_MPEG;
+  } else if (!strcasecmp (ptype, "asf")) {
+    filetype = LIBMTP_FILETYPE_ASF;
+  } else if (!strcasecmp (ptype, "qt") || !strcasecmp (ptype, "mov")) {
+    filetype = LIBMTP_FILETYPE_QT;
+  } else if (!strcasecmp (ptype, "wma")) {
+    filetype = LIBMTP_FILETYPE_WMA;
+  } else if (!strcasecmp (ptype, "jpg") || !strcasecmp (ptype, "jpeg")) {
+    filetype = LIBMTP_FILETYPE_JPEG;
+  } else if (!strcasecmp (ptype, "jfif")) {
+    filetype = LIBMTP_FILETYPE_JFIF;
+  } else if (!strcasecmp (ptype, "tif") || !strcasecmp (ptype, "tiff")) {
+    filetype = LIBMTP_FILETYPE_TIFF;
+  } else if (!strcasecmp (ptype, "bmp")) {
+    filetype = LIBMTP_FILETYPE_BMP;
+  } else if (!strcasecmp (ptype, "gif")) {
+    filetype = LIBMTP_FILETYPE_GIF;
+  } else if (!strcasecmp (ptype, "pic") || !strcasecmp (ptype, "pict")) {
+    filetype = LIBMTP_FILETYPE_PICT;
+  } else if (!strcasecmp (ptype, "png")) {
+    filetype = LIBMTP_FILETYPE_PNG;
+  } else if (!strcasecmp (ptype, "wmf")) {
+    filetype = LIBMTP_FILETYPE_WINDOWSIMAGEFORMAT;
+  } else if (!strcasecmp (ptype, "ics")) {
+    filetype = LIBMTP_FILETYPE_VCALENDAR2;
+  } else if (!strcasecmp (ptype, "exe") || !strcasecmp (ptype, "com") ||
+	     !strcasecmp (ptype, "bat") || !strcasecmp (ptype, "dll") ||
+	     !strcasecmp (ptype, "sys")) {
+    filetype = LIBMTP_FILETYPE_WINEXEC;
+  } else if (!strcasecmp (ptype, "aac")) {
+    filetype = LIBMTP_FILETYPE_AAC;
+  } else if (!strcasecmp (ptype, "mp2")) {
+    filetype = LIBMTP_FILETYPE_MP2;
+  } else if (!strcasecmp (ptype, "flac")) {
+    filetype = LIBMTP_FILETYPE_FLAC;
+  } else if (!strcasecmp (ptype, "m4a")) {
+    filetype = LIBMTP_FILETYPE_M4A;
+  } else if (!strcasecmp (ptype, "doc")) {
+    filetype = LIBMTP_FILETYPE_DOC;
+  } else if (!strcasecmp (ptype, "xml")) {
+    filetype = LIBMTP_FILETYPE_XML;
+  } else if (!strcasecmp (ptype, "xls")) {
+    filetype = LIBMTP_FILETYPE_XLS;
+  } else if (!strcasecmp (ptype, "ppt")) {
+    filetype = LIBMTP_FILETYPE_PPT;
+  } else if (!strcasecmp (ptype, "mht")) {
+    filetype = LIBMTP_FILETYPE_MHT;
+  } else if (!strcasecmp (ptype, "jp2")) {
+    filetype = LIBMTP_FILETYPE_JP2;
+  } else if (!strcasecmp (ptype, "jpx")) {
+    filetype = LIBMTP_FILETYPE_JPX;
+  } else if (!strcasecmp (ptype, "bin")) {
+    filetype = LIBMTP_FILETYPE_FIRMWARE;
+  } else if (!strcasecmp (ptype, "vcf")) {
+    filetype = LIBMTP_FILETYPE_VCARD3;
+  } else {
+    /* Tagging as unknown file type */
+    filetype = LIBMTP_FILETYPE_UNKNOWN;
+  }
+  printf("type: %s, %d\n", ptype, filetype);
+  return filetype;
+}
+
+/* Function that compensate for missing libgen.h on Windows */
+#ifndef HAVE_LIBGEN_H
+static char *basename(char *in) {
+  char *p;
+
+  if (in == NULL)
+    return NULL;
+  p = in + strlen(in) - 1;
+  while (*p != '\\' && *p != '/' && *p != ':')
+    { p--; }
+  return ++p;
+}
+#endif
diff --git a/examples/pathutils.h b/examples/pathutils.h
new file mode 100644
index 0000000..f40b6d6
--- /dev/null
+++ b/examples/pathutils.h
@@ -0,0 +1,29 @@
+/** 
+ * \file pathutils.h
+ *
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef PATHUTILS_H_INCLUSION_GUARD
+#define PATHUTILS_H_INCLUSION_GUARD
+int parse_path (char *, LIBMTP_file_t *, LIBMTP_folder_t *);
+LIBMTP_filetype_t find_filetype (const char *);
+int progress (const uint64_t, const uint64_t, void const * const); 
+#ifndef HAVE_LIBGEN_H
+char *basename(char *in);
+#endif
+#endif
diff --git a/examples/playlists.c b/examples/playlists.c
new file mode 100644
index 0000000..1416c61
--- /dev/null
+++ b/examples/playlists.c
@@ -0,0 +1,82 @@
+/** 
+ * \file playlists.c
+ * Example program to list the playlists on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+
+static void dump_plinfo(LIBMTP_mtpdevice_t *device, LIBMTP_playlist_t *pl)
+{
+  uint32_t i;
+
+  printf("Playlist ID: %d\n", pl->playlist_id);
+  if (pl->name != NULL)
+    printf("   Name: %s\n", pl->name);
+  printf("   Parent ID: %d\n", pl->parent_id);
+  printf("   Tracks:\n");
+
+  for (i = 0; i < pl->no_tracks; i++) {
+    LIBMTP_track_t *track;
+    
+    track = LIBMTP_Get_Trackmetadata(device, pl->tracks[i]);
+    if (track != NULL) {
+      printf("      %u: %s - %s\n", pl->tracks[i], track->artist, track->title);
+      LIBMTP_destroy_track_t(track);
+    } else {
+      printf("      %u: INVALID TRACK REFERENCE!\n", pl->tracks[i]);
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    }
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  LIBMTP_playlist_t *playlists;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    exit (0);
+  }
+  
+  // Get playlist listing.
+  playlists = LIBMTP_Get_Playlist_List(device);
+  if (playlists == NULL) {
+    printf("No playlists.\n");
+  } else {
+    LIBMTP_playlist_t *pl, *tmp;
+    pl = playlists;
+    while (pl != NULL) {
+      dump_plinfo(device, pl);
+      tmp = pl;
+      pl = pl->next;
+      LIBMTP_destroy_playlist_t(tmp);
+    }
+  }
+    
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
diff --git a/examples/reset.c b/examples/reset.c
new file mode 100644
index 0000000..f8ef376
--- /dev/null
+++ b/examples/reset.c
@@ -0,0 +1,85 @@
+/** 
+ * \file reset.c
+ * Example program that resets the device.
+ *
+ * Copyright (C) 2007 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+
+/**
+ * Returns 0 if OK (yes), 1 if not OK (no)
+ */
+static int prompt()
+{
+  char buff[2];
+  
+  while (1) {
+    fprintf(stdout, "> ");
+    if ( fgets(buff, sizeof(buff), stdin) == NULL ) {
+      if (ferror(stdin)) {
+        fprintf(stderr, "File error on stdin\n");
+      } else {
+        fprintf(stderr, "EOF on stdin\n");
+      }
+      return 1;
+    }
+    if (buff[0] == 'y') {
+      return 0;
+    } else if (buff[0] == 'n') {
+      return 1;
+    }
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  int ret;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+
+  printf("I will now reset your device. This means that\n");
+  printf("the device may go inactive immediately and may report errors.\n");
+  printf("Continue? (y/n)\n");
+  if (prompt() == 0) {
+    ret = LIBMTP_Reset_Device(device);
+  } else {
+    printf("Aborted.\n");
+    ret = 0;
+  }
+
+  if ( ret != 0 ) {
+    printf("Failed to reset device.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+    LIBMTP_Release_Device(device);
+    return 1;
+  }
+
+  // It is not possible to release the device after successful reset!
+  // LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
diff --git a/examples/sendfile.c b/examples/sendfile.c
new file mode 100644
index 0000000..3155622
--- /dev/null
+++ b/examples/sendfile.c
@@ -0,0 +1,102 @@
+/** 
+ * \file sendfile.c
+ * Example program to send an arbitrary file to a device.
+ *
+ * Copyright (C) 2005-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <libgen.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "common.h"
+#include "libmtp.h"
+#include "pathutils.h"
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+int sendfile_function(char *, char *);
+void sendfile_command(int, char **);
+void sendfile_usage(void);
+
+void sendfile_usage(void)
+{
+  fprintf(stderr, "usage: sendfile <local filename> <remote filename>\n");
+}
+
+int sendfile_function(char * from_path, char *to_path)
+{
+  printf("Sending %s to %s\n",from_path,to_path);
+  char *filename;
+  uint64_t filesize;
+  struct stat sb;
+  LIBMTP_file_t *genfile;
+  int ret;
+  uint32_t parent_id = 0;
+
+  if ( stat(from_path, &sb) == -1 ) {
+    fprintf(stderr, "%s: ", from_path);
+    perror("stat");
+    exit(1);
+  }
+
+  filesize = sb.st_size;
+  filename = basename(from_path);
+  parent_id = parse_path (to_path,files,folders);
+  if (parent_id == -1) {
+    printf("Parent folder could not be found, skipping\n");
+    return 0;
+  }
+  
+  genfile = LIBMTP_new_file_t();
+  genfile->filesize = filesize;
+  genfile->filename = strdup(filename);
+  genfile->filetype = find_filetype (filename);
+  genfile->parent_id = parent_id;
+  genfile->storage_id = 0;
+
+  printf("Sending file...\n");
+  ret = LIBMTP_Send_File_From_File(device, from_path, genfile, progress, NULL);
+  printf("\n");
+  if (ret != 0) {
+    printf("Error sending file.\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  } else {
+    printf("New file ID: %d\n", genfile->item_id);
+  }
+
+  LIBMTP_destroy_file_t(genfile);
+
+  return 0;
+}
+
+void sendfile_command (int argc, char **argv) {
+  if (argc < 3) {
+    sendfile_usage();
+    return;
+  }
+  sendfile_function(argv[1],argv[2]);
+}
diff --git a/examples/sendtr.c b/examples/sendtr.c
new file mode 100644
index 0000000..212c088
--- /dev/null
+++ b/examples/sendtr.c
@@ -0,0 +1,443 @@
+/** 
+ * \file sendtr.c
+ * Example program to send a music track to a device.
+ * This program is derived from the exact equivalent in libnjb.
+ * based on Enrique Jorreto Ledesma's work on the original program by 
+ * Shaun Jackman and Linus Walleij.
+ *
+ * Copyright (C) 2003-2009 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2003-2005 Shaun Jackman
+ * Copyright (C) 2003-2005 Enrique Jorrete Ledesma
+ * Copyright (C) 2006 Chris A. Debenham <chris@adebenham.com>
+ * Copyright (C) 2008 Nicolas Pennequin <nicolas.pennequin@free.fr>
+ * Copyright (C) 2008 Joseph Nahmias <joe@nahmias.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+#include "common.h"
+#include "util.h"
+#include <stdlib.h>
+#include <limits.h>
+#include <string.h>
+#include <libgen.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#include "libmtp.h"
+#include "pathutils.h"
+
+extern LIBMTP_folder_t *folders;
+extern LIBMTP_file_t *files;
+extern LIBMTP_mtpdevice_t *device;
+
+int sendtrack_function (char *, char *, char *, char *, char *, char *, char *, char *, uint16_t, uint16_t, uint16_t, uint32_t);
+void sendtrack_command (int, char **);
+void sendtrack_usage (void);
+
+void sendtrack_usage (void)
+{
+  fprintf(stderr, "usage: sendtr [ -D debuglvl ] [ -q ]\n");
+  fprintf(stderr, "-t <title> -a <artist> -A <Album artist> -w <writer or composer>\n");
+  fprintf(stderr, "    -l <album> -c <codec> -g <genre> -n <track number> -y <year>\n");
+  fprintf(stderr, "       -d <duration in seconds> -s <storage_id> <local path> <remote path>\n");
+  fprintf(stderr, "(-q means the program will not ask for missing information.)\n");
+}
+
+static char *prompt (const char *prompt, char *buffer, size_t bufsz, int required)
+{
+  char *cp, *bp;
+  
+  while (1) {
+    fprintf(stdout, "%s> ", prompt);
+    if ( fgets(buffer, bufsz, stdin) == NULL ) {
+      if (ferror(stdin)) {
+	perror("fgets");
+      } else {
+	fprintf(stderr, "EOF on stdin\n");
+      }
+      return NULL;
+    }
+    
+    cp = strrchr(buffer, '\n');
+    if ( cp != NULL ) *cp = '\0';
+    
+    bp = buffer;
+    while ( bp != cp ) {
+      if ( *bp != ' ' && *bp != '\t' ) return bp;
+      bp++;
+    }
+    
+    if (! required) return bp;
+  }
+}
+
+static int add_track_to_album(LIBMTP_album_t *albuminfo, LIBMTP_track_t *trackmeta)
+{
+  LIBMTP_album_t *album;
+  LIBMTP_album_t *found_album = NULL;
+  int ret;
+
+  /* Look for the album */
+  album = LIBMTP_Get_Album_List(device);
+  while(album != NULL) {
+    if ((album->name != NULL &&
+	album->artist != NULL &&
+	!strcmp(album->name, albuminfo->name) &&
+	!strcmp(album->artist, albuminfo->artist)) ||
+	  (album->name != NULL &&
+	album->composer != NULL &&
+	!strcmp(album->name, albuminfo->name) &&
+	!strcmp(album->composer, albuminfo->composer))) {
+      /* Disconnect this album for later use */
+      found_album = album;
+      album = album->next;
+      found_album->next = NULL;
+    } else {
+      LIBMTP_album_t *tmp;
+
+      tmp = album;
+      album = album->next;
+      LIBMTP_destroy_album_t(tmp);
+    }
+  }
+  
+  if (found_album != NULL) {
+    uint32_t *tracks;
+
+    tracks = (uint32_t *)malloc((found_album->no_tracks+1) * sizeof(uint32_t));
+    printf("Album \"%s\" found: updating...\n", found_album->name);
+    if (!tracks) {
+      printf("failed malloc in add_track_to_album()\n");
+      return 1;
+    }
+    found_album->no_tracks++;
+    if (found_album->tracks != NULL) {
+      memcpy(tracks, found_album->tracks, found_album->no_tracks * sizeof(uint32_t));
+      free(found_album->tracks);
+    }
+    tracks[found_album->no_tracks-1] = trackmeta->item_id;
+    found_album->tracks = tracks;
+    ret = LIBMTP_Update_Album(device, found_album);
+    LIBMTP_destroy_album_t(found_album);
+  } else {
+    uint32_t *trackid;
+    
+    trackid = (uint32_t *)malloc(sizeof(uint32_t));
+    *trackid = trackmeta->item_id;
+    albuminfo->tracks = trackid;
+    albuminfo->no_tracks = 1;
+    albuminfo->storage_id = trackmeta->storage_id;
+    printf("Album doesn't exist: creating...\n");
+    ret = LIBMTP_Create_New_Album(device, albuminfo);
+    /* albuminfo will be destroyed later by caller */
+  }
+  
+  if (ret != 0) {
+    printf("Error creating or updating album.\n");
+    printf("(This could be due to that your device does not support albums.)\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  } else {
+    printf("success!\n");
+  }
+  return ret;
+}
+
+int sendtrack_function(char * from_path, char * to_path, char *partist, char *palbumartist, char *ptitle, char *pgenre, char *palbum, char *pcomposer, uint16_t tracknum, uint16_t length, uint16_t year, uint32_t storageid)
+{
+  char *filename, *parent;
+  char artist[80], albumartist[80], title[80], genre[80], album[80], composer[80];
+  char num[80];
+  uint64_t filesize;
+  uint32_t parent_id = 0;
+  struct stat sb;
+  LIBMTP_track_t *trackmeta;
+  LIBMTP_album_t *albuminfo;
+  int ret;
+
+  printf("Sending track %s to %s\n",from_path,to_path);
+
+  trackmeta = LIBMTP_new_track_t();
+  albuminfo = LIBMTP_new_album_t();
+
+  parent = dirname(strdup(to_path));
+  filename = basename(strdup(to_path));
+  parent_id = parse_path (parent,files,folders);
+  if (parent_id == -1) {
+    printf("Parent folder could not be found, skipping\n");
+    return 1;
+  }
+
+  if ( stat(from_path, &sb) == -1 ) {
+    fprintf(stderr, "%s: ", from_path);
+    perror("stat");
+    return 1;
+  } else if (S_ISREG (sb.st_mode)) {
+    filesize = sb.st_size;
+    trackmeta->filetype = find_filetype (from_path);
+    if (!LIBMTP_FILETYPE_IS_TRACK(trackmeta->filetype)) {
+      printf("Not a valid track codec: \"%s\"\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
+      return 1;
+    }
+
+    if (ptitle == NULL) {
+      ptitle = prompt("Title", title, 80, 0);
+    }
+    if (!strlen(ptitle))
+      ptitle = NULL;
+
+    if (palbum == NULL) {
+      palbum = prompt("Album", album, 80, 0);
+    }
+    if (!strlen(palbum))
+      palbum = NULL;
+
+    if (palbumartist == NULL) {
+      palbumartist = prompt("Album artist", albumartist, 80, 0);
+    }
+    if (partist == NULL) {
+      partist = prompt("Artist", artist, 80, 0);
+    }
+    if (!strlen(partist))
+      partist = NULL;
+
+    if (pcomposer == NULL) {
+      pcomposer = prompt("Writer or Composer", composer, 80, 0);
+    }
+    if (!strlen(pcomposer))
+      pcomposer = NULL;
+
+    if (pgenre == NULL) {
+      pgenre = prompt("Genre", genre, 80, 0);
+    }
+    if (!strlen(pgenre))
+      pgenre = NULL;
+
+    if (tracknum == 0) {
+      char *pnum;
+      if ( (pnum = prompt("Track number", num, 80, 0)) == NULL )
+      tracknum = 0;
+      if ( strlen(pnum) ) {
+        tracknum = strtoul(pnum, 0, 10);
+      } else {
+        tracknum = 0;
+      }
+    }
+
+    if (year == 0) {
+      char *pnum;
+      if ( (pnum = prompt("Year", num, 80, 0)) == NULL )
+        year = 0;
+      if ( strlen(pnum) ) {
+        year = strtoul(pnum, 0, 10);
+      } else {
+        year = 0;
+      }
+    }
+
+    if (length == 0) {
+      char *pnum;
+      if ( (pnum = prompt("Length", num, 80, 0)) == NULL )
+        length = 0;
+      if ( strlen(pnum) ) {
+        length = strtoul(pnum, 0, 10);
+      } else {
+        length = 0;
+      }
+    }
+    
+    printf("Sending track:\n");
+    printf("Codec:     %s\n", LIBMTP_Get_Filetype_Description(trackmeta->filetype));
+    if (ptitle) {
+      printf("Title:     %s\n", ptitle);
+      trackmeta->title = strdup(ptitle);
+    }
+    if (palbum) {
+      printf("Album:     %s\n", palbum);
+      trackmeta->album = strdup(palbum);
+      albuminfo->name = strdup(palbum);
+    }
+    if (palbumartist) {
+      printf("Album artist:    %s\n", palbumartist);
+      albuminfo->artist = strdup(palbumartist);
+    }
+    if (partist) {
+      printf("Artist:    %s\n", partist);
+      trackmeta->artist = strdup(partist);
+      if (palbumartist == NULL)
+      albuminfo->artist = strdup(partist);
+    }
+
+    if (pcomposer) {
+      printf("Writer or Composer:    %s\n", pcomposer);
+      trackmeta->composer = strdup(pcomposer);
+      albuminfo->composer = strdup(pcomposer);
+    }
+    if (pgenre) {
+      printf("Genre:     %s\n", pgenre);
+      trackmeta->genre = strdup(pgenre);
+      albuminfo->genre = strdup(pgenre);
+    }
+    if (year > 0) {
+      char tmp[80];
+      printf("Year:      %d\n", year);
+      snprintf(tmp, sizeof(tmp)-1, "%4d0101T0000.0", year);
+      tmp[sizeof(tmp)-1] = '\0';
+      trackmeta->date = strdup(tmp);
+    }
+    if (tracknum > 0) {
+      printf("Track no:  %d\n", tracknum);
+      trackmeta->tracknumber = tracknum;
+    }
+    if (length > 0) {
+      printf("Length:    %d\n", length);
+      // Multiply by 1000 since this is in milliseconds
+      trackmeta->duration = length * 1000;
+    }
+    // We should always have this
+    if (filename != NULL) {
+      trackmeta->filename = strdup(filename);
+    }
+    trackmeta->filesize = filesize;
+    trackmeta->parent_id = parent_id;
+    {
+        int rc;
+        char *desc = NULL;
+        LIBMTP_devicestorage_t *pds = NULL;
+
+        if ( 0 != (rc=LIBMTP_Get_Storage(device, LIBMTP_STORAGE_SORTBY_NOTSORTED)) )
+        {
+            perror("LIBMTP_Get_Storage()");
+            exit(-1);
+        }
+        for (pds = device->storage; pds != NULL; pds = pds->next)
+        {
+            if (pds->id == storageid)
+            {
+                desc = strdup(pds->StorageDescription);
+                break;
+            }
+        }
+        if (NULL != desc)
+        {
+            printf("Storage ID: %s (%u)\n", desc, storageid);
+            free(desc);
+        }
+        else
+            printf("Storage ID: %u\n", storageid);
+        trackmeta->storage_id = storageid;
+    }
+      
+    printf("Sending track...\n");
+    ret = LIBMTP_Send_Track_From_File(device, from_path, trackmeta, progress, NULL);
+    printf("\n");
+    if (ret != 0) {
+      printf("Error sending track.\n");
+      LIBMTP_Dump_Errorstack(device);
+      LIBMTP_Clear_Errorstack(device);
+    } else {
+      printf("New track ID: %d\n", trackmeta->item_id);
+    }
+
+    /* Add here add to album call */
+    if (palbum)
+      ret = add_track_to_album(albuminfo, trackmeta);
+
+    LIBMTP_destroy_album_t(albuminfo);
+    LIBMTP_destroy_track_t(trackmeta);
+
+    return 0;
+  }
+  return 0;
+}
+
+void sendtrack_command (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  char *partist = NULL;
+  char *palbumartist = NULL;
+  char *pcomposer = NULL;
+  char *ptitle = NULL;
+  char *pgenre = NULL;
+  char *pcodec = NULL;
+  char *palbum = NULL;
+  uint16_t tracknum = 0;
+  uint16_t length = 0;
+  uint16_t year = 0;
+  uint16_t quiet = 0;
+  uint32_t storageid = 0;
+  while ( (opt = getopt(argc, argv, "qD:t:a:A:w:l:c:g:n:d:y:s:")) != -1 ) {
+    switch (opt) {
+    case 't':
+      ptitle = strdup(optarg);
+      break;
+    case 'a':
+      partist = strdup(optarg);
+      break;
+    case 'A':
+      palbumartist = strdup(optarg);
+      break;
+    case 'w':
+      pcomposer = strdup(optarg);
+      break;
+    case 'l':
+      palbum = strdup(optarg);
+      break;
+    case 'c':
+      pcodec = strdup(optarg); // FIXME: DSM check for MP3, WAV or WMA
+      break;
+    case 'g':
+      pgenre = strdup(optarg);
+      break;
+    case 'n':
+      tracknum = atoi(optarg);
+      break;
+    case 's':
+      storageid = (uint32_t) strtoul(optarg, NULL, 0);
+      break;
+    case 'd':
+      length = atoi(optarg);
+      break;
+    case 'y':
+      year = atoi(optarg);
+      break;
+    case 'q':
+      quiet = 1;
+      break;
+    default:
+      sendtrack_usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+  
+  if ( argc != 2 ) {
+    printf("You need to pass a filename and destination.\n");
+    sendtrack_usage();
+    return;
+  }
+
+  checklang();
+  
+  printf("%s,%s,%s,%s,%s,%s,%s,%s,%d%d,%d,%u\n",argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer,tracknum, length, year, storageid);
+  sendtrack_function(argv[0],argv[1],partist,palbumartist,ptitle,pgenre,palbum,pcomposer, tracknum, length, year, storageid);
+}
diff --git a/examples/thumb.c b/examples/thumb.c
new file mode 100644
index 0000000..2718a0c
--- /dev/null
+++ b/examples/thumb.c
@@ -0,0 +1,131 @@
+/** 
+ * \file thumb.c
+ * Example program to send and associate album art to an entity 
+ * on a device.
+ *
+ * Copyright (C) 2006 Robert Reardon <rreardon@monkshatch.vispa.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "config.h"
+#include "common.h"
+#include "string.h"
+#include <fcntl.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <limits.h>
+#include <sys/types.h>
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+#include <sys/stat.h>
+
+static void usage(void) {
+  printf("Usage: thumb -i <fileid/trackid> <imagefile>\n");
+  exit(0);
+}
+
+int main (int argc, char **argv) {
+  int opt;
+  extern int optind;
+  extern char *optarg;
+  LIBMTP_mtpdevice_t *device = NULL;
+  int fd;
+  uint32_t id = 0;
+  uint64_t filesize;
+  uint8_t *imagedata = NULL;
+  char *path = NULL;
+  char *rest;
+  struct stat statbuff;
+  int ret;
+
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  while ( (opt = getopt(argc, argv, "hi:")) != -1 ) {
+    switch (opt) {
+    case 'h':
+      usage();
+    case 'i':
+      id = strtoul(optarg, &rest, 0);
+      break;
+    default:
+      usage();
+    }
+  }
+  argc -= optind;
+  argv += optind;
+
+  if ( argc != 1 ) {
+    printf("You need to pass a filename.\n");
+    usage();
+  }
+
+  path = argv[0];
+
+  if ( stat(path, &statbuff) == -1 ) {
+    fprintf(stderr, "%s: ", path);
+    perror("stat");
+    exit(1);
+  }
+  filesize = (uint64_t) statbuff.st_size;
+  imagedata = malloc(filesize * sizeof(uint16_t));
+
+#ifdef __WIN32__
+  if ( (fd = open(path, O_RDONLY|O_BINARY) == -1) ) {
+#else
+  if ( (fd = open(path, O_RDONLY)) == -1) {
+#endif
+    printf("Couldn't open image file %s (%s)\n",path,strerror(errno));
+    return 1;
+  }
+  else {
+    read(fd, imagedata, filesize);
+    close(fd);
+  }
+
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices.\n");
+    return 0;
+  }
+  
+  LIBMTP_filesampledata_t *thumb = LIBMTP_new_filesampledata_t();
+
+  int i;
+  thumb->data = malloc(sizeof(uint16_t) * filesize);
+  for (i = 0; i < filesize; i++) {
+    thumb->data[i] = imagedata[i];
+  }
+
+  thumb->size = filesize;
+  thumb->filetype = LIBMTP_FILETYPE_JPEG;
+  
+  ret = LIBMTP_Send_Representative_Sample(device,id,thumb);
+  if (ret != 0) {
+    printf("Couldn't send thumbnail\n");
+    LIBMTP_Dump_Errorstack(device);
+    LIBMTP_Clear_Errorstack(device);
+  }
+
+  free(imagedata);
+  LIBMTP_destroy_filesampledata_t(thumb);
+
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  return 0;
+}
diff --git a/examples/tracks.c b/examples/tracks.c
new file mode 100644
index 0000000..262a8c8
--- /dev/null
+++ b/examples/tracks.c
@@ -0,0 +1,148 @@
+/** 
+ * \file tracks.c
+ * Example program to list the tracks on a device.
+ *
+ * Copyright (C) 2005-2007 Linus Walleij <triad@df.lth.se>
+ * Copyright (C) 2007 Ted Bullock <tbullock@canada.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+
+static void dump_trackinfo(LIBMTP_track_t *track)
+{
+  printf("Track ID: %u\n", track->item_id);
+  if (track->title != NULL)
+    printf("   Title: %s\n", track->title);
+  if (track->artist != NULL)
+    printf("   Artist: %s\n", track->artist);
+  if (track->genre != NULL)
+    printf("   Genre: %s\n", track->genre);
+  if (track->composer != NULL)
+    printf("   Composer: %s\n", track->composer);
+  if (track->album != NULL)
+    printf("   Album: %s\n", track->album);
+  if (track->date != NULL)
+    printf("   Date: %s\n", track->date);
+  if (track->filename != NULL)
+    printf("   Origfilename: %s\n", track->filename);
+  printf("   Track number: %d\n", track->tracknumber);
+  printf("   Duration: %d milliseconds\n", track->duration);
+#ifdef __WIN32__
+  printf("   File size %I64u bytes\n", track->filesize);
+#else
+  printf("   File size %llu bytes\n", (long long unsigned int) track->filesize);
+#endif
+  printf("   Filetype: %s\n", LIBMTP_Get_Filetype_Description(track->filetype));
+  if (track->samplerate != 0) {
+    printf("   Sample rate: %u Hz\n", track->samplerate);
+  }
+  if (track->nochannels != 0) {
+    printf("   Number of channels: %u\n", track->nochannels);
+  }
+  if (track->wavecodec != 0) {
+    printf("   WAVE fourCC code: 0x%08X\n", track->wavecodec);
+  }
+  if (track->bitrate != 0) {
+    printf("   Bitrate: %u bits/s\n", track->bitrate);
+  }
+  if (track->bitratetype != 0) {
+    if (track->bitratetype == 1) {
+      printf("   Bitrate type: Constant\n");
+    } else if (track->bitratetype == 2) {
+      printf("   Bitrate type: Variable (VBR)\n");
+    } else if (track->bitratetype == 3) {
+      printf("   Bitrate type: Free\n");
+    } else {
+      printf("   Bitrate type: Unknown/Erroneous value\n");
+    }
+  }
+  if (track->rating != 0) {
+    printf("   User rating: %u (out of 100)\n", track->rating);
+  }
+  if (track->usecount != 0) {
+    printf("   Use count: %u times\n", track->usecount);
+  }
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device_list, *iter;
+  LIBMTP_track_t *tracks;
+
+  LIBMTP_Init();
+  fprintf(stdout, "Attempting to connect device(s)\n");
+
+  switch(LIBMTP_Get_Connected_Devices(&device_list))
+  {
+  case LIBMTP_ERROR_NO_DEVICE_ATTACHED:
+    fprintf(stdout, "mtp-tracks: No Devices have been found\n");
+    return 0;
+  case LIBMTP_ERROR_CONNECTING:
+    fprintf(stderr, "mtp-tracks: There has been an error connecting. Exit\n");
+    return 1;
+  case LIBMTP_ERROR_MEMORY_ALLOCATION:
+    fprintf(stderr, "mtp-tracks: Memory Allocation Error. Exit\n");
+    return 1;
+ 
+  /* Unknown general errors - This should never execute */
+  case LIBMTP_ERROR_GENERAL:
+  default:
+    fprintf(stderr, "mtp-tracks: Unknown error, please report "
+                    "this to the libmtp developers\n");
+  return 1;
+
+  /* Successfully connected at least one device, so continue */
+  case LIBMTP_ERROR_NONE:
+    fprintf(stdout, "mtp-tracks: Successfully connected\n");
+    fflush(stdout);
+  }
+  
+  /* iterate through connected MTP devices */
+  for(iter = device_list; iter != NULL; iter = iter->next)
+  {
+  	char *friendlyname;
+    /* Echo the friendly name so we know which device we are working with */
+    friendlyname = LIBMTP_Get_Friendlyname(iter);
+    if (friendlyname == NULL) {
+      printf("Friendly name: (NULL)\n");
+    } else {
+      printf("Friendly name: %s\n", friendlyname);
+      free(friendlyname);
+    }
+  
+	  // Get track listing.
+	  tracks = LIBMTP_Get_Tracklisting_With_Callback(iter, NULL, NULL);
+	  if (tracks == NULL) {
+	    printf("No tracks.\n");
+	  } else {
+	    LIBMTP_track_t *track, *tmp;
+	    track = tracks;
+	    while (track != NULL) {
+	      dump_trackinfo(track);
+	      tmp = track;
+	      track = track->next;
+	      LIBMTP_destroy_track_t(tmp);
+	    }
+	  }
+  }
+    
+  LIBMTP_Release_Device_List(device_list);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/trexist.c b/examples/trexist.c
new file mode 100644
index 0000000..d6159d7
--- /dev/null
+++ b/examples/trexist.c
@@ -0,0 +1,68 @@
+/** 
+ * \file trexist.c
+ * Example program to check if a certain track exists on the device.
+ *
+ * Copyright (C) 2006 The libmtp development team. 
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "common.h"
+#include <stdlib.h>
+#include <limits.h>
+
+static void usage (void)
+{
+  fprintf(stderr, "trexist <trackid>\n");
+}
+
+int main (int argc, char **argv)
+{
+  LIBMTP_mtpdevice_t *device;
+  uint32_t id;
+  char *endptr;
+  
+  fprintf(stdout, "libmtp version: " LIBMTP_VERSION_STRING "\n\n");
+
+  // We need track ID 
+  if ( argc != 2 ) {
+    usage();
+    return 1;
+  }
+
+  // Sanity check song ID
+  id = strtoul(argv[1], &endptr, 10);
+  if ( *endptr != 0 ) {
+    fprintf(stderr, "illegal value %s\n", argv[1]);
+    return 1;
+  } else if ( ! id ) {
+    fprintf(stderr, "bad song id %u\n", id);
+    return 1;
+  }
+  
+  LIBMTP_Init();
+  device = LIBMTP_Get_First_Device();
+  if (device == NULL) {
+    printf("No devices. Connect/replug device and try again.\n");
+    exit (0);
+  }
+  
+  printf("%s\n", LIBMTP_Track_Exists(device, id) ? "Yes" : "No");
+  
+  LIBMTP_Release_Device(device);
+  printf("OK.\n");
+  exit (0);
+}
+
diff --git a/examples/util.c b/examples/util.c
new file mode 100644
index 0000000..f71f722
--- /dev/null
+++ b/examples/util.c
@@ -0,0 +1,63 @@
+/** 
+ * \file util.c
+ * A set of common utility functions found
+ * in all samples.
+ *
+ * Copyright (C) 2008 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "util.h"
+#ifdef HAVE_LANGINFO_H
+#include <langinfo.h>
+#endif
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#endif
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+void checklang(void)
+{
+  char *langsuff = NULL;
+  char *lang = getenv("LANG");
+
+#ifdef HAVE_LOCALE_H
+  // Set the locale in accordance with environment
+  setlocale(LC_ALL, "");
+#endif
+#ifdef HAVE_LANGINFO_H
+  langsuff = nl_langinfo(CODESET);
+#else
+  /*
+   * Check environment variables $LANG and $LC_CTYPE
+   * to see if we want to support UTF-8 unicode
+   */
+  if (lang != NULL) {
+    if (strlen(lang) > 5) {
+      langsuff = &lang[strlen(lang)-5];
+    }
+  }
+#endif
+  if (langsuff == NULL) {
+    printf("Could not determine language suffix for your system. Please check your setup!\n");
+  } else if (strcmp(langsuff, "UTF-8")) {
+    printf("Your system does not appear to have UTF-8 enabled ($LANG=\"%s\")\n", lang);
+    printf("If you want to have support for diacritics and Unicode characters,\n");
+    printf("please switch your locale to an UTF-8 locale, e.g. \"en_US.UTF-8\".\n");
+  }
+}
diff --git a/examples/util.h b/examples/util.h
new file mode 100644
index 0000000..ca7b658
--- /dev/null
+++ b/examples/util.h
@@ -0,0 +1,26 @@
+/** 
+ * \file util.h
+ * Header for a set of common utility functions found
+ * in all samples.
+ *
+ * Copyright (C) 2008 Linus Walleij <triad@df.lth.se>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef LIBMTP_EXAMPLES_UTIL_H
+#define LIBMTP_EXAMPLES_UTIL_H
+void checklang(void);
+#endif