You can get a lot more information using different modifiers:
%~0 - expands %I removing any surrounding quotes (")
%~f0 - expands %I to a fully qualified path name
%~d0 - expands %I to a drive letter only
%~p0 - expands %I to a path only
%~n0 - expands %I to a file name only
%~x0 - expands %I to a file extension only
%~s0 - expanded path contains short names only
%~a0 - expands %I to file attributes of file
%~t0 - expands %I to date/time of file
%~z0 - expands %I to size of file
The modifiers can be combined to get compound results:
%~dp0 - expands %I to a drive letter and path only (same as %cd%)
%~nx0 - expands %I to a file name and extension only
%~fs0 - expands %I to a full path name with short names only
Eg: C:\Temp>batchparams.bat c:\windows\notepad.exe
| %~1 |
= |
c:\windows\notepad.exe |
| %~f1 |
= |
c:\WINDOWS\NOTEPAD.EXE |
| %~d1 |
= |
c: |
| %~p1 |
= |
\WINDOWS\ |
| %~n1 |
= |
NOTEPAD |
| %~x1 |
= |
.EXE |
| %~s1 |
= |
c:\WINDOWS\NOTEPAD.EXE |
| %~a1 |
= |
--a------ |
| %~t1 |
= |
08/25/2005 01:50 AM |
| %~z1 |
= |
17920 |
| %~$PATHATH:1 |
= |
|
| %~dp1 |
= |
c:\WINDOWS\ |
| %~nx1 |
= |
NOTEPAD.EXE |
| %~dp$PATH:1 |
= |
c:\WINDOWS\ |
| %~ftza1 |
= |
--a------ 08/25/2005 01:50 AM 17920 c:\WINDOWS\NOTEPAD.EXE |
How to get Current Folder name in a batch file
@echo off
set source=%cd%
set folder=
for /f "tokens=*" %%a in ("%source%") do set folder=%%~na
echo The users folder name is %folder%
OR
for /F "delims=\" %%I in ("%CD%") do set e=%%~nI
echo.FolderName: %e%
Links