I figured something out today - HOW TO: Separate filename and directory from a path. This is really fun! The idea I had was to allow me to drag and drop a file onto a batch file and have it spit out the MD5 code for it. Simple right?... hardly... Here's the code... @echo off REM Check to see if filename is specified if %1.==. goto end set filename=%1 REM Remove double quotes from filename for /f "tokens=1* usebackq delims=?" %%i IN ('%filename%') DO ( set filename=%%~i ) REM Build directory path set dir_path= :loop for /f "tokens=1,2* usebackq delims=\" %%i IN ('%filename%') DO ( set dir_path=%dir_path%%%i\ if not %%k.==. ( set filename=%%j\%%k goto loop ) set filename=%%j ) echo DIRPATH:%dir_path% echo FILENAME:%filename% pause :end
Blog about science and technology, especially software development and space ships. ;) Blake is a software developer who specializes in building inventory management and project management solutions for small or mid-sized businesses. He also spends a fair amount of time on embedded software and database research.