本文介绍了枚举目录中文件的相对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成一个文件,其中包含目录中所有文件的相对路径.到目前为止,我有这个批处理文件:

I want to generate a file containing the relative paths to all the files in a directory. So far I have this batch file:

@echo off
for /R  "C:\TEST" %%f in (*) do echo %%f

其输出是:

C:\TEST\linux.txt
C:\TEST\riddles.txt
C:\TEST\one\limerick.txt
C:\TEST\two\art.txt
C:\TEST\two\computers.txt

我希望输出为:

linux.txt
riddles.txt
one\limerick.txt
two\art.txt
two\computers.txt

推荐答案

您可以尝试

@echo off
    setlocal enableextensions disabledelayedexpansion

    pushd "c:\test"
    for /f "tokens=* delims=\." %%a in ('
        xcopy /l /s ".\*" "%temp%" ^| find "."
    ') do echo %%a
    popd

这使用xcopy来获取具有相对路径的文件列表. delimstokens子句将从每行的开头删除初始的.\,并且find命令将丢弃显示文件数量的xcopy输出中的最后一行.

This uses an xcopy to get the list of files with relative paths. The delims and tokens clauses will remove the initial .\ from the start of each line, and the find command will discard the final line in the xcopy output that shows the number of files.

这篇关于枚举目录中文件的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 01:58
查看更多