问题描述
描述:结果
我想用这样的COMP我一个语法:\\文件夹1 Z:\\文件夹2的所有文件比较我我和Z驱动器的内容驱动。我只需要比较他们的名字,看看一个在其他exsists。我需要的,因为有很多位于两个驱动器递归到子目录,我知道我需要使用for循环和PUSHD POPD和命令使用批处理脚本。
Description:
I want to use a syntax like COMP I:\folder1 Z:\folder2 to compare all files in my I drive with the content of my z drive. I only need to compare their names to see if one exsists in the other. I need to recurse into the subdirectories because there are many located in both drives, I understand I need to use a batch script using a FOR loop and the PUSHD and POPD command.
问题:结果
我该怎么做呢?
QUESTION:
How do I do this?
推荐答案
这从对输出/?
FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]
Walks the directory tree rooted at [drive:]path, executing the FOR
statement in each directory of the tree. If no directory
specification is specified after /R then the current directory is
assumed. If set is just a single period (.) character then it
will just enumerate the directory tree.
所以,你会做这样的事情。
So you'd do something like
@echo off
setlocal enabledelayedexpansion ENABLEEXTENSIONS
for /R P:\ %%F in (*.*) DO (
set fileFull=%%~fF
set filePath=%%~pF
set fileDrive=%%~dF
set fileName=%%~nF
set fileExtension=%%~xF
call :checker "!filePath!" "!fileName!" "!fileExtension!"
)
goto :eof
:checker
set fileTarget="c:%~1%~2%~3"
if not exist %fileTarget% echo %fileTarget% not found
goto :eof
在此情况下,脚本越来越P中所有的文件名:\\及其子目录,并告诉我,如果该文件不相同的路径上存在C:
In this case, the script is getting all the filenames in P:\ and its subdirectories and telling me if the file doesn't exist on the same path in C:
这篇关于在Windows命令提示符比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!