How can one convert a path with relative components to an absolute path in a windows batch file? -


given path relative components:

c:\foo\..\temp\file.txt 

i want "remove/expand" relative part,

c:\temp\file.txt 

how can convert path relative components absolute path in windows batch file?

@echo off setlocal enableextensions disabledelayedexpansion set "relative=c:\foo\..\temp\file.txt"  %%a in ("%relative%") set "absolute=%%~fa"  echo %relative% = %absolute% 

use modifiers in for (technet documentation) replaceable parameters full path indicated element (see for /? full list)

%~i        expands %i removes surrounding quotation marks (""). %~fi       expands %i qualified path name. %~di       expands %i drive letter only. %~pi       expands %i path only. %~ni       expands %i file name only. %~xi       expands %i file extension only. %~si       expands path contain short names only. %~ai       expands %i file attributes of file. %~ti       expands %i date , time of file. %~zi       expands %i size of file. %~$path:i  searches directories listed in path environment variable ,            expands %i qualified name of first 1 found. if            environment variable name not defined or file not            found search, modifier expands empty string. 

will work same files or folders , same if exist or not.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -