|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『楼 主』:
如何用批处理命令判断2个文件名是否相同?
使用 LLM 解释/回答一下
C:\Target\1.txt
S:\Source\1.txt
如何用批处理命令判断这两个文件名一样?
当一样时,不做任何操作;
当不一样时,覆盖拷贝S:\Source\文件夹里的所有内容到C:\Target\文件夹里。
To determine if the two file names are the same using batch commands:
First, get the file names of the two files. Then compare them. If they are the same, do nothing. If they are different, copy all contents from the S:\Source\ folder to the C:\Target\ folder.
The following is the batch code example:
```batch
@echo off
set "target_file=C:\Target\1.txt"
set "source_file=S:\Source\1.txt"
for %%i in ("%target_file%") do set "target_name=%%~nxi"
for %%j in ("%source_file%") do set "source_name=%%~nxi"
if "%target_name%"=="%source_name%" (
echo The file names are the same, no operation.
) else (
xcopy "S:\Source\" "C:\Target\" /e /y
)
```
|
|
2010-6-15 11:37 |
|
|
keeds
新手上路

积分 11
发帖 8
注册 2010-6-10
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
dir /a-d /b "源文件夹路径">temp.txt
for /f %%i in (temp.txt) do (IF NOT EXIST "目标文件夹路径\%%i" move "源文件夹路径\%%i" "目标文件夹路径")
del temp.txt
dir /a-d /b "Source folder path" > temp.txt
for /f %%i in (temp.txt) do (IF NOT EXIST "Target folder path\%%i" move "Source folder path\%%i" "Target folder path")
del temp.txt
|
|
2010-6-15 12:09 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
不太明白,尤其是第一行dir /a-d /b "源文件夹路径">temp.txt
还有for /f %%i in (temp.txt)
这两句什么意思?起了什么作用?
I don't quite understand, especially the first line dir /a-d /b "source folder path">temp.txt
And for /f %%i in (temp.txt)
What do these two sentences mean? What role do they play?
|
|
2010-6-15 12:36 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
我的目的是这样的,C:\Target和S:\Source这2个文件夹中的内容应该是一样的,如果S:\Source中的内容变了,就要将S:\Source中的全部文件拷贝去C:\Target中,所以我在C:\Target和S:\Source建了一个txt的文件用来标识版本(根据文件名),整个文件夹里只有这一个文件是txt格式的。
所以这个批处理要执行的内容就是以下内容:
1. 获取C:\Target中的txt文件的文件名
2. 判断在S:\Source中是否有存在和C:\Target中的txt文件同名的文件
3. 如果有同名的文件,则不做任何操作,如果没有同名的文件,覆盖拷贝S:\Source\文件夹里的所有内容到C:\Target\文件夹里
My purpose is like this: The contents in the two folders C:\Target and S:\Source should be the same. If the contents in S:\Source change, all the files in S:\Source should be copied to C:\Target. So I created a txt file in both C:\Target and S:\Source to identify the version (according to the file name). There is only this txt - formatted file in the entire folder.
So the content that this batch processing should execute is the following content:
1. Get the file name of the txt file in C:\Target
2. Judge whether there is a file with the same name as the txt file in C:\Target in S:\Source
3. If there is a file with the same name, do nothing. If there is no file with the same name, copy all the contents in the S:\Source\ folder to the C:\Target\ folder
|
|
2010-6-15 12:54 |
|
|
keeds
新手上路

积分 11
发帖 8
注册 2010-6-10
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
dir /a-d /b "C:\Target\">temp.txt
将C:\Target\里除了文件夹以外的文件名称导出到temp.txt里
for /f %%i in (temp.txt)
循环读取temp.txt里每一行(就是C:\Target\里面的文件名,比如1.txt,2.txt)
dir /a-d /b "C:\Target\">temp.txt
Export the names of files (excluding folders) in C:\Target\ to temp.txt
for /f %%i in (temp.txt)
Loop to read each line in temp.txt (which are the file names in C:\Target\, such as 1.txt, 2.txt)
|
|
2010-6-15 12:55 |
|
|
keeds
新手上路

积分 11
发帖 8
注册 2010-6-10
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by ChengXu at 2010-6-15 12:54:
我的目的是这样的,C:\Target和S:\Source这2个文件夹中的内容应该是一样的,如果S:\Source中的内容变了,就要将S:\Source中的全部文件拷贝去C:\Target中,所以 ...
for /f %%i in (C:\Target\1.txt) do (IF NOT EXIST "C:\Target\%%i" move "S:\Source\%%i" "C:\Target")
Originally posted by ChengXu at 2010-6-15 12:54:
My purpose is like this. The contents in the two folders C:\Target and S:\Source should be the same. If the contents in S:\Source change, all files in S:\Source should be copied to C:\Target. So ...
for /f %%i in (C:\Target\1.txt) do (IF NOT EXIST "C:\Target\%%i" move "S:\Source\%%i" "C:\Target")
|
|
2010-6-15 12:59 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
不需要弄一个1.txt: xcopy S:\Source C:\Target /zfdi
1,如果要再包括子目录,最后写/zfdis
2,如果要再包括只读文件,最后写/zfdisr
3,如果要再包括隐藏或系统属性文件,最后写/zfdisrh
4,如果要再包括空目录,最后写/zfdisrhe
5,如果要再带着DACL权限,最后写/zfdisrheo
6,如果要再带着SACL权限,最后写/zfdisrhex
Last edited by Hanyeguxing on 2010-6-15 at 13:45 ]
No need to make a 1.txt:
xcopy S:\Source C:\Target /zfdi
1. If you want to include subdirectories, finally write /zfdis
2. If you want to include read-only files, finally write /zfdisr
3. If you want to include hidden or system attribute files, finally write /zfdisrh
4. If you want to include empty directories, finally write /zfdisrhe
5. If you want to carry DACL permissions, finally write /zfdisrheo
6. If you want to carry SACL permissions, finally write /zfdisrhex
Last edited by Hanyeguxing on 2010-6-15 at 13:45 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-6-15 13:42 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by keeds at 2010-6-15 12:59:
for /f %%i in (C:\Target\1.txt) do (IF NOT EXIST "C:\Target\%%i" move "S:\Source\%%i" "C:\Target")
还是不对啊,因为那个txt文本是我用来标记版本号的,所以它的名字每次都是不同的,如果batchfile里固定了名字,那我每次还要改batchfile。
有没有办法是可以先获得C:\Target\里面的txt的文件名(只有一个txt文件),
然后再判断是否有同名文件在S:\Source里,如果有,copy S:\Source 中的内容到 C:\Target\ 中
Originally posted by keeds at 2010-6-15 12:59:
for /f %%i in (C:\Target\1.txt) do (IF NOT EXIST "C:\Target\%%i" move "S:\Source\%%i" "C:\Target")
Still not right, because that txt file is used to mark the version number, so its name is different each time. If the batch file has a fixed name, then I have to change the batch file every time.
Is there a way to first get the file name of the txt in C:\Target\ (there is only one txt file),
then judge whether there is a file with the same name in S:\Source. If there is, copy the content in S:\Source to C:\Target\
|
|
2010-6-15 16:23 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by Hanyeguxing at 2010-6-15 13:42:
不需要弄一个1.txt:xcopy S:\Source C:\Target /zfdi
1,如果要再包括子目录,最后写/zfdis
2,如果要再包括只读文件,最后写/zfdisr
3,如果要再包 ...
因为整个文件夹比较大,全部Copy需要较长时间,如果S:\Source没有变更(即S:\Source中的那个用来标记版本号的txt文件名与C:\Target中的那个txt文件名相同)就不进行Copy的动作,如果不同,才Copy。
有办法吗?
Originally posted by Hanyeguxing at 2010-6-15 13:42:
No need to make a 1.txt:
xcopy S:\Source C:\Target /zfdi
1. If you need to include subdirectories, finally write /zfdis
2. If you need to include read-only files, finally write /zfdisr
3. If you need to include ...
Because the entire folder is relatively large, it will take a long time to copy all. If there is no change in S:\Source (that is, the file name of the txt used to mark the version number in S:\Source is the same as that in C:\Target), then do not perform the copy action; if different, then copy. Is there a way?
|
|
2010-6-15 16:27 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
/d参数本身就是比对是否发生修改的参数。只有当修改、不同时才自动复制需要的部分。
例如:
1,某些文件存在于源目录,而目标目录中不存在,则复制这些文件
2,某些文件同时存在于源目录和目标目录,则比较最后修改时间,只有源目标中的文件比目标目录中的文件更新时,才复制这些文件。
/u参数,以目标目录为样本,只复制目标目录中存在的文件。
当/d和/u一起使用时,就排除了只在源目录中的文件,而只比对两个目录同时存在的文件的最后修改时间:/du
Last edited by Hanyeguxing on 2010-6-15 at 17:00 ]
The /d parameter itself is the parameter for comparing whether there is a modification. Only when there is a modification or difference will the required part be automatically copied.
For example:
1. Some files exist in the source directory but not in the target directory, then these files are copied.
2. Some files exist in both the source directory and the target directory, then compare the last modification time. Only when the file in the source target is newer than the file in the target directory will these files be copied.
The /u parameter takes the target directory as a sample and only copies the files that exist in the target directory.
When /d and /u are used together, it excludes the files that are only in the source directory, and only compares the last modification time of the files that exist in both directories: /du
Last edited by Hanyeguxing on 2010-6-15 at 17:00 ]
|

批处理之家 http://bbs.bathome.net/forum-5-1.html |
|
2010-6-15 16:51 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by Hanyeguxing at 2010-6-15 16:51:
/d参数本身就是比对是否发生修改的参数。只有当修改、不同时才自动复制需要的部分。
例如:
1,某些文件存在于源目录,而目标目录中不存在,则 ...
原来是这样啊!
真是太神奇了!
我想请问下我在什么地方可以查到z、f、d、i等等这些参数的含义呢?
说实话我在百度上面搜的时候都不知道该搜什么关键字。
Originally posted by Hanyeguxing at 2010-6-15 16:51:
The /d parameter itself is a parameter for comparing whether a modification has occurred. Only when there is a modification or a difference will it automatically copy the necessary parts.
For example:
1. Some files exist in the source directory but not in the target directory, then...
Oh, so that's how it is!
It's really amazing!
I want to ask where I can find the meanings of parameters like z, f, d, i, etc.?
To be honest, when I searched on Baidu, I didn't know what keywords to search for.
|
|
2010-6-15 17:55 |
|
|
Hanyeguxing
银牌会员
     正在学习中的菜鸟...
积分 1039
发帖 897
注册 2009-3-1 来自 在地狱中仰望天堂
状态 离线
|
|
2010-6-15 19:02 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
直接在命令行中运行 XCOPY /?
谢谢楼上所有帮我解答问题的朋友
该问题解决了谢谢啊!
Run `XCOPY /?` directly in the command line.
Thanks to all the friends who helped me solve the problem upstairs.
The problem is solved, thank you!
|
|
2010-6-15 20:45 |
|
|
ChengXu
新手上路

积分 18
发帖 18
注册 2010-6-15
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
晕!24小时只能评2点分数啊?!
不好意思!楼上还有没评分的朋友,我下次再来评!
谢谢大家!
Oh, what a bummer! You can only rate 2 points within 24 hours?!
Sorry! There are still friends above who haven't rated, I'll come back to rate next time!
Thank you everyone!
|
|
2010-6-15 20:47 |
|