Split directory name & filename from a string
Posted: 29 Jan 2009 12:56
Wondering if there is any way to split directory name & filename from a string that contains a complete path of file including filename.
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
@echo off
Set filename=C:\Documents and Settings\All Users\Desktop\Dostips.cmd
For %%A in ("%filename%") do (
Set Folder=%%~dpA
Set Name=%%~nxA
)
echo.Folder is: %Folder%
echo.Name is: %Name%
Folder is: C:\Documents and Settings\All Users\Desktop\
Name is: Dostips.cmd
Code: Select all
Set LookUpSet=Dir /b/s File1* File2*
For /F %%F In ('%LookUpSet%') DO (
Echo;
Echo Path: %%~fF
Echo File: %%~nxF
Echo;
Pause
)
Code: Select all
Path: C:\Documents
File: Documents
Code: Select all
Set LookUpSet=Dir /b/s File1* File2*
For /F "delim=" %%F In ('%LookUpSet%') DO (
Echo;
Echo Path: %%~fF
Echo File: %%~nxF
Echo;
Pause
)
Code: Select all
Set LookUpSet=Dir /b/s File1* File2 File3*
For /F "Delims=" %%F In ('%LookUpSet%') DO (
Set "f=%%~nxF"
Set "p=%%~pF"
CD /D "!p!"
Call :LogMsg "Flagged for Removal"
Call :RemoveFile
Call :LogMsg "Removed"
)
Code: Select all
:: File Removal
:RemoveFile
Echo --Changing Directory to: !p!
CD /D !p!
Echo --Removing File: !f!
Call :LogMsg "Removing !f! from Folder..."
SDelete -p 5 !f!
Goto:EOF