使用Windows Batchrecursion地打印文件夹和文件

可能重复:
Windows批处理(文件)

你好 。 我试图做一个批处理脚本打印每个文件名从命令行文件夹的所有子文件夹,其中find文件(我有作为参数文件夹和文件名列表)。 子文件夹名称应按文件大小的降序排列(文件在不同的子文件夹中可以有不同的大小)。 我找不到打印path的脚本。 谁能帮忙?

@echo off REM check the numbers of parameters if "%2"=="" goto err1 REM check: is first parameter a directory? if NOT EXIST %1\NUL goto err2 set d=%1 shift REM iterate the rest of the parametersa for %%i in %dir% ( find %dir /name %i > temp if EXIST du /b temp | cut /f 1 goto err3 myvar=TYPE temp echo "file " %i "is in: " for %%j in %myvar do echo %j echo after sort du /b %myvar | sort /nr ) :err1 echo Two parameters are necessary goto end :err2 echo First parameter must be a directory. :err3 echo file does not exist. :end 

Solutions Collecting From Web of "使用Windows Batchrecursion地打印文件夹和文件"

这里有一个脚本,有点做你想要的,抱歉拖延很长时间。

 @echo off REM application logic. askForDir. [askForFile => findFile]{infinity} :askForDir cls set basePath= echo Not supplying a directory will exit. Trailing slash please set /p basePath=Search in directory: if x%basePath%==x goto endApp REM Gets a file name, sets the curDir :askForFile cls set fileName= echo Currently searching in: '%basePath%' echo Not supplying a filename will return you to directory selection set /p fileName=Search for file: if x%fileName%==x goto askForDir REM We know what we're searching for and where set file=%basePath%%fileName% if exist %file% ( echo %file% ) REM check recursively for the fileName in each subfolder FOR /R %basePath% %%f IN (%fileName%) DO ( echo %%f ) REM Finished dir and all subs, askForFile again echo Done. pause>nul goto askForFile REM Finished :endApp cls echo We hope you enjoyed this presentation. pause>nul 

虽然jeb指出,我建议学习一些基础知识,考虑到这是作业,如果你没有真正学会如何做,它不会帮助你。 试图评论我的代码尽可能多的理解,但尝试阅读更多关于使用批处理文件 。