T3RRYT3RR0R

poison_Char_Handling_Example.bat

Jun 14th, 2026 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 1.48 KB | Source Code | 0 0
  1. @echo off & Setlocal EnableExtensions DisableDelayedExpansion
  2. cd /d "%~dp0"
  3. REM This script creates the below directory and file [in this scripts working folder]
  4. REM to demonstrate the example. These are Removed via RD at end of script.
  5. if not exist "%~dp0tes!%%this%%_,&~^" MD "%~dp0tes!%%this%%_,&~^"
  6. if not exist "%~dp0tes!%%this%%_,&~^\!%%th!s%%~&test.txt" break>"%~dp0tes!%%this%%_,&~^\!%%th!s%%~&test.txt"
  7.  
  8. For /R "%~dp0tes!%%this%%_,&~^" %%G in (*) DO (
  9.   Echo(Drive:        %%~dG
  10.   Set "_Drive=%%~dG"
  11.   Echo(Folder:       %%~pG
  12.   Set "_Folder=%%~pG"
  13.   Echo(FileName:     %%~nG
  14.   Set "_FileName=%%~nG"
  15.   Echo(Extension:    %%~xG
  16.   Set "_Extension=%%~xG"
  17.   Echo(FileName.Ext: %%~nxG
  18.   Set "_FileName.Ext=%%~nxG"
  19.   Echo(FullPath:     %%~fG
  20.   Set "_FullPath=%%~fG"
  21.   Echo(FolderPath:   %%~dpG
  22.   Set "_FolderPath=%%~dpG"
  23.   Call:GetParent _FolderPath _FileName.ext
  24. )
  25.  
  26. RD /S /Q "%~dp0tes!%%this%%_,&~^"
  27. Pause
  28. Endlocal & Goto:eof
  29.  
  30. :GetParent <FolderPath> <filename.ext>
  31.   Echo(
  32.   Setlocal EnableDelayedExpansion
  33.  REM to modify a variable safely regardless of character content use Delayed expansion
  34.  REM in conjunction with a for /f loop to capture the variable into a metavariable
  35.  REM and 'tunnel' the modified string across endlocal using a codeblock like follows
  36.  
  37.   For /f "Tokens=1,2,3 Delims=:" %%G in ("!%~1:~,-1!:!%~2!") Do Endlocal & (
  38.     Set "$Parent=%%~nH"
  39.     Set "$Root=%%~dpH"
  40.     Set "$FileName=%%~nI"
  41.     Set "$FileExt=%%~xI"
  42.   )
  43.  
  44.   Set $
  45.  
  46. goto:Eof
  47.  
  48.  
Tags: batch
Advertisement
Add Comment
Please, Sign In to add comment