MENU

遍历文件和目录的bat

February 6, 2014 • Security

有网站源码了 测试网站有越权访问和 扫描后门的时候可以用到

::ref:[url=http://stackoverflow.com/questions/8487489/batch-programming-get-relative-path-of-file]http://stackoverflow.com/questio ... lative-path-of-file[/url]

@echo off & setlocal enabledelayedexpansion

set rootdir=%~dp0
set foo=%rootdir%
set cut=
:loop
if not "!foo!"=="" (
    set /a cut += 0
    set foo=!foo:~1!
    goto :loop
)
echo Root dir: %rootdir%
echo strlen  : %cut%

:: also remove leading /
set /a cut += 1
 
for /R %rootdir% %%F in (.,*) do (
    set B=%%~fF
    ::take substring of the path
    set B=!B:~%cut%!
    ::echo Full    : %%F 
    echo Partial : \!B!

        echo \!B!>>%~n0.txt
)
echo ''
echo result saved in %~n0.txt .
echo ''
pause
Archives QR Code
QR Code for this page
Tipping QR Code