Board logo

标题: [分享]批处理递归算法 [打印本页]

作者: genteman     时间: 2007-12-19 16:40    标题: [分享]批处理递归算法

花了一天的时间研究出来的,希望对大家有用。
CODE:  [Copy to clipboard]

::genteman - 2007-12-19 -CMD@WinXP Pro
::contact amdaround@163.com
@echo off
setlocal enabledelayedexpansion
if "%~1"=="" exit /b
if not exist %~s1\nul exit /b
cd "%~1"
%~d1
:rec
if exist "%cd%\*.txt" (
for /f "delims=" %%p in ('cd') do set filename="%%~np"
type *.txt>"..\!filename: =!.txt"
)
for /f %%i in ('dir "%cd%" /ad /b') do (
pushd "%cd%"
cd "%%i"
call :rec
popd
)
[ Last edited by genteman on 2007-12-20 at 09:13 AM ]
作者: genteman     时间: 2007-12-19 16:45
下面的代码用for命令提供的功能实现
CODE:  [Copy to clipboard]
::genteman - 2007-12-19 -CMD@WinXP Pro
::contact amdaround@163.com
rem @echo off

if "%~1"=="" exit /b
if not exist %~s1\nul exit /b

for /r "%~1" %%i in (.) do (
cd "%%~fi"
%%~di
if exist *.txt type "*.txt">..\"%%~ni.txt"
)
[ Last edited by genteman on 2007-12-20 at 09:13 AM ]
作者: genteman     时间: 2007-12-19 16:46
用for命令提供的功能另一种实现方法
CODE:  [Copy to clipboard]
::genteman - 2007-12-19 -CMD@WinXP Pro
::contact amdaround@163.com
rem @echo off
if "%~1"=="" exit /b
if not exist %~s1\nul exit /b

for /f "delims=" %%i in ('dir "%~1" /ad /b /s') do (
cd "%%~fi"
%%~di
if exist *.txt type "*.txt">..\"%%~ni.txt"
)
[ Last edited by genteman on 2007-12-20 at 09:14 AM ]




欢迎光临 中国DOS联盟论坛 (http://cndos.fam.cx/forum/) Powered by Discuz! 2.5