Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off & Setlocal EnableExtensions DisableDelayedExpansion
- cd /d "%~dp0"
- REM This script creates the below directory and file [in this scripts working folder]
- REM to demonstrate the example. These are Removed via RD at end of script.
- if not exist "%~dp0tes!%%this%%_,&~^" MD "%~dp0tes!%%this%%_,&~^"
- if not exist "%~dp0tes!%%this%%_,&~^\!%%th!s%%~&test.txt" break>"%~dp0tes!%%this%%_,&~^\!%%th!s%%~&test.txt"
- For /R "%~dp0tes!%%this%%_,&~^" %%G in (*) DO (
- Echo(Drive: %%~dG
- Set "_Drive=%%~dG"
- Echo(Folder: %%~pG
- Set "_Folder=%%~pG"
- Echo(FileName: %%~nG
- Set "_FileName=%%~nG"
- Echo(Extension: %%~xG
- Set "_Extension=%%~xG"
- Echo(FileName.Ext: %%~nxG
- Set "_FileName.Ext=%%~nxG"
- Echo(FullPath: %%~fG
- Set "_FullPath=%%~fG"
- Echo(FolderPath: %%~dpG
- Set "_FolderPath=%%~dpG"
- Call:GetParent _FolderPath _FileName.ext
- )
- RD /S /Q "%~dp0tes!%%this%%_,&~^"
- Pause
- Endlocal & Goto:eof
- :GetParent <FolderPath> <filename.ext>
- Echo(
- Setlocal EnableDelayedExpansion
- REM to modify a variable safely regardless of character content use Delayed expansion
- REM in conjunction with a for /f loop to capture the variable into a metavariable
- REM and 'tunnel' the modified string across endlocal using a codeblock like follows
- For /f "Tokens=1,2,3 Delims=:" %%G in ("!%~1:~,-1!:!%~2!") Do Endlocal & (
- Set "$Parent=%%~nH"
- Set "$Root=%%~dpH"
- Set "$FileName=%%~nI"
- Set "$FileExt=%%~xI"
- )
- Set $
- goto:Eof
Advertisement
Add Comment
Please, Sign In to add comment