to willsort版主:
really pretty good :)
谢谢,使用如下的code
@echo off & setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('"dir /a/s/b/on *.*"') do (
set file=%%~fi
set file=!file:%cd%\=!
set file=!file:\=/!
echo !file! >> 内容.txt
)
可以将所有文件相对于搜索路径(当前目录)的相对路径输出,但是也同时将所有目录进行输出了。
参考了咱们论坛上另外一个帖子:如何判断参数是文件还是目录
http://www.cn-dos.net/forum/viewthread.php?tid=20999&fpage=1&highlight=%E5%88%A4%E6%96%AD
判断是否存在目录: if exist "%~f1\" ...
判断是否存在文件: if exist "%~f1" if not exist "%~f1\"...
写了如下的批处理:文件列表输出至file.txt,目录列表输出至directory.txt
@echo off
::for /r /d %%d in (*.*) do if exist "%%d\*.*" echo %%d >>content.txt
for /f %%i in ('"dir /a /s /b *.*"') do call :next "%%i"
pause
goto :eof
:next
set jpg=%1
set cd1=%cd:\=/%
set jpg=%jpg:\=/%
rem echo %%jpg:%cd1%=%% | findstr .
for /f %%j in ('"echo %%jpg:%cd1%=%% | findstr . "') do set last=%%j
set last=%last:"=%
call :checkFD %last%
echo %last% >> content.txt
goto :eof
:checkFD
if exist "%~f1\" echo %1>>directory.txt
if exist "%~f1" if not exist "%~f1\" echo %1>>file.txt
goto :EOF
问题:
在file.txt 还有directory.txt中只有一行记录。
检查了几遍code,觉得没有问题啊。请教