|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『楼 主』:
[已解决]带文件夹相对路径复制指定的N个文件
使用 LLM 解释/回答一下
大家好!
偶现在做一个操作系统配置的文件备份批处理,想达到的效果是:把批处理文件放在任何一个文件夹内,并运行它后,则它按批处理文件里的文件路径清单复制到当前文件夹,并且是带原文件路径的。
===============
@echo off
@eho c:\IBM\123\456\789.nsf
@eho c:\IBM\abc\cd.id
@eho c:\Lotus\abc\cd.js
:这一行代码是关键,就是COPY上面两个文件到当前文件夹,并且这2个文件是复制到当前文件夹+原路径下的目录内。 ???
exit
================
示例:
在E盘根目录下的bak文件夹内运行这个批处理后,则会产生如下效果:
E:\bak\IBM\123\456\789.nsf
E:\bak\IBM\abc\cd.id
E:\bak\Lotus\abc\cd.js
在F盘根目录下的load文件夹内运行这个批处理后,则会产生如下效果:
F:\load\IBM\123\456\789.nsf
F:\load\IBM\abc\cd.id
F:\load\Lotus\abc\cd.js
请教各位如何写批处理?bat或vbs都可以,谢谢!
Last edited by flying008 on 2008-4-15 at 12:35 PM ]
Hello everyone!
I am currently making a batch script for backing up files for operating system configuration. The desired effect is: place the batch script in any folder and run it, then it copies the files listed in the file path in the batch script to the current folder, and retains the original file path.
===============
@echo off
@eho c:\IBM\123\456\789.nsf
@eho c:\IBM\abc\cd.id
@eho c:\Lotus\abc\cd.js
:This line of code is the key, which is to COPY the above two files to the current folder, and these 2 files are copied to the directory under the current folder + original path. ???
exit
================
Example:
After running this batch script in the bak folder under the root directory of drive E, the following effect will be produced:
E:\bak\IBM\123\456\789.nsf
E:\bak\IBM\abc\cd.id
E:\bak\Lotus\abc\cd.js
After running this batch script in the load folder under the root directory of drive F, the following effect will be produced:
F:\load\IBM\123\456\789.nsf
F:\load\IBM\abc\cd.id
F:\load\Lotus\abc\cd.js
Please ask everyone how to write the batch script? Both bat or vbs are acceptable, thank you!
Last edited by flying008 on 2008-4-15 at 12:35 PM ]
|
|
2008-4-11 17:05 |
|
|
tvzml
初级用户
 
积分 157
发帖 67
注册 2007-5-13
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
这个简单,下面这句就满足你要求了。
xcopy /d/r/y/e/h %cd% E:\bak\
This is simple, the following line meets your requirement.
xcopy /d/r/y/e/h %cd% E:\bak\
|
|
2008-4-11 17:18 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Originally posted by tvzml at 2008-4-11 17:18:
这个简单,下面这句就满足你要求了。
xcopy /d/r/y/e/h %cd% E:\bak\
这句偶还没试效果,不过要是放在F盘的up文件夹运行呢?呵呵……目的是生成
当前文件夹路径+原路径+文件的,
COPY上面N个文件到当前文件夹,并且这N个文件是复制到当前文件夹+原路径下的目录内
所以你把E:\bak\作为当前文件夹路径写入批处理中是不合适的,不过还是要谢谢你的帮助!
Last edited by flying008 on 2008-4-11 at 05:25 PM ]
Originally posted by tvzml at 2008-4-11 17:18:
This is simple, the following line meets your requirement.
xcopy /d/r/y/e/h %cd% E:\bak\
I haven't tried the effect of this sentence yet, but what if it runs in the up folder on drive F? Hehe... The purpose is to generate the current folder path + the original path + the file.
COPY the above N files to the current folder, and these N files are copied into the directory under the current folder + the original path.
So it is inappropriate to write E:\bak\ as the current folder path in the batch processing, but still thank you for your help!
Last edited by flying008 on 2008-4-11 at 05:25 PM ]
|
|
2008-4-11 17:24 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
只是感觉这样的功能要用FOR加上XCOPY来实现,但还没有头绪,请大大指教!
I just feel that such a function should be implemented with FOR plus XCOPY, but I haven't got a clue yet. Please give me some guidance, sir!
|
|
2008-4-12 12:28 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 5 楼』:
自己测试吧:
使用 LLM 解释/回答一下
@echo off
set a=c:\IBM\123\456\789.nsf&set b=c:\IBM\abc\cd.id&set c=c:\Lotus\abc\cd.js
for /f "delims=" %%i in ('cd') do copy %a% %%i%a:~2%© %b% %%i%b:~2%© %c% %%i%c:~2%
Last edited by zw19750516 on 2008-4-12 at 12:43 PM ]
@echo off
set a=c:\IBM\123\456\789.nsf&set b=c:\IBM\abc\cd.id&set c=c:\Lotus\abc\cd.js
for /f "delims=" %%i in ('cd') do copy %a% %%i%a:~2%© %b% %%i%b:~2%© %c% %%i%c:~2%
Last edited by zw19750516 on 2008-4-12 at 12:43 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-12 12:40 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
@echo off
set a=C:\Documents and Settings\Administrator\Application Data\Microsoft\AddIns\polynimials.chm
for /f "delims=" %%i in ('cd') do copy %a% %%i%a:~2%
经过测试,只能复制磁盘根目录下文件到当前文件夹下,这样的功能单独用COPY命令就可以做到了。
如果是某文件夹下的文件或多级子文件夹下的文件,无论是否路径有空格,提示系统找不到指定的文件! 且不能生成所需要的多级文件目录.
革命尚未成功,还请大大指点啊!谢谢……
Last edited by flying008 on 2008-4-12 at 03:25 PM ]
@echo off
set a=C:\Documents and Settings\Administrator\Application Data\Microsoft\AddIns\polynimials.chm
for /f "delims=" %%i in ('cd') do copy %a% %%i%a:~2%
After testing, it can only copy files in the root directory of the disk to the current folder. Such a function can be achieved with the COPY command alone.
If it is a file in a certain folder or a file in a multi-level subfolder, no matter whether the path has spaces or not, it prompts that the specified file is not found by the system! And it cannot generate the required multi-level file directory.
The revolution is not yet successful, still please big shots give pointers! Thank you...
Last edited by flying008 on 2008-4-12 at 03:25 PM ]
|
|
2008-4-12 15:15 |
|
|
abcd
银牌会员
    
积分 1436
发帖 739
注册 2007-10-11
状态 离线
|
 『第 7 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "tokens=*" %%i in ('more +7 "%~0"') do (
echo f|xcopy /e/q "%%i" "%cd%%%~pnxi">nul
)
pause
goto :eof
c:\IBM\123\456\789.nsf
c:\IBM\abc\cd.id
c:\Lotus\abc\cd.js
Last edited by abcd on 2008-4-12 at 03:38 PM ]
```batch
@echo off
for /f "tokens=*" %%i in ('more +7 "%~0"') do (
echo f|xcopy /e/q "%%i" "%cd%%%~pnxi">nul
)
pause
goto :eof
c:\IBM\123\456\789.nsf
c:\IBM\abc\cd.id
c:\Lotus\abc\cd.js
```
Last edited by abcd on 2008-4-12 at 03:38 PM ]
|
|
2008-4-12 15:37 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
abcd大大,你好!
运行这个bat时提示内部错误,请问如何修改后才能用这个bat来复制下面3个文件?
c:\IBM\123\456\789.nsf
c:\IBM\abc\cd.id
c:\Lotus\abc\cd.js
Last edited by flying008 on 2008-4-14 at 11:15 AM ]
Hello, Mr. abcd!
When running this bat, an internal error is prompted. May I ask how to modify it so that this bat can be used to copy the following 3 files?
c:\IBM\123\456\789.nsf
c:\IBM\abc\cd.id
c:\Lotus\abc\cd.js
Last edited by flying008 on 2008-4-14 at 11:15 AM ]
|
|
2008-4-14 11:13 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
 『第 9 楼』:
修改如下:
使用 LLM 解释/回答一下
@echo off
set a=c:\IBM&set b=c:\IBM&set c=c:\Lotus
for /f "delims=" %%i in ('cd') do xcopy /e %a% %%i%a:~2%\&xcopy /e %b% %%i%b:~2%\&xcopy /e %c% %%i%c:~2%\
Last edited by zw19750516 on 2008-4-14 at 01:18 PM ]
```
@echo off
set a=c:\IBM&set b=c:\IBM&set c=c:\Lotus
for /f "delims=" %%i in ('cd') do xcopy /e %a% %%i%a:~2%\&xcopy /e %b% %%i%b:~2%\&xcopy /e %c% %%i%c:~2%\
```
Last edited by zw19750516 on 2008-4-14 at 01:18 PM ]
|

批处理之家新域名:www.bathome.net |
|
2008-4-14 12:48 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by zw19750516 at 2008-4-14 12:48:
@echo off
set a=c:\IBM&set b=c:\IBM&set c=c:\Lotus
for /f "delims=" %%i in ('cd') do xcopy /e %a% %%i%a:~2%\&xcopy /e %b% %%i%b:~2%\&xcopy /e %c% %%i%c:~2%\ ...
此段代码没有指定源文件,如何复制?
把上面改为set a=c:\IBM\456\78j9.txt 则只复制这文件到当前目录,还是没有原路径层级文件夹
Last edited by flying008 on 2008-4-14 at 01:43 PM ]
Originally posted by zw19750516 at 2008-4-14 12:48:
@echo off
set a=c:\IBM&set b=c:\IBM&set c=c:\Lotus
for /f "delims=" %%i in ('cd') do xcopy /e %a% %%i%a:~2%\&xcopy /e %b% %%i%b:~2%\&xcopy /e %c% %%i%c:~2%\ ...
This code doesn't specify the source file. How to copy?
If you change the above to set a=c:\IBM\456\78j9.txt, then only this file is copied to the current directory, and the original path-level folders are still not there
Last edited by flying008 on 2008-4-14 at 01:43 PM ]
|
|
2008-4-14 13:35 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
xcopy /e命令是指复制文件夹里所有的内容啊(包括空文件夹),你测试了没有啊?
The xcopy /e command means to copy all the contents in the folder (including empty folders). Did you test it?
|

批处理之家新域名:www.bathome.net |
|
2008-4-14 15:05 |
|
|
moniuming
银牌会员
     永远的菜鸟
积分 1335
发帖 574
注册 2007-11-27 来自 广西
状态 离线
|
 『第 12 楼』:
使用 LLM 解释/回答一下
没有比这更笨的方法了,但一定能实现(目录级数如果不一样,请作相应改变):
@echo off
set aa=c:\IBM\123\456\789.nsf
set ab=c:\IBM\abc\cd.id
set ac=c:\Lotus\abc\cd.js
set path=%cd%
for /f "tokens=2-4 delims=\" %%a in ("%aa%") do (
md %%a&cd %%a&&md %%b&cd %%b&&md %%c&cd %%c
copy /y "%aa%"
)
cd %path%
for /f "tokens=2,3 delims=\" %%i in ("%ab%") do (
md %%i&cd %%i&&md %%j&cd %%j
copy /y "%ab%"
)
cd %path%
for /f "tokens=2,3 delims=\" %%m in ("%ac%") do (
md %%m&cd %%m&&md %%n&cd %%n
copy /y "%ac%"
)
pause
There is no more foolish way than this, but it must be achievable (if the number of directory levels is different, make corresponding changes):
@echo off
set aa=c:\IBM\123\456\789.nsf
set ab=c:\IBM\abc\cd.id
set ac=c:\Lotus\abc\cd.js
set path=%cd%
for /f "tokens=2-4 delims=\" %%a in ("%aa%") do (
md %%a&cd %%a&&md %%b&cd %%b&&md %%c&cd %%c
copy /y "%aa%"
)
cd %path%
for /f "tokens=2,3 delims=\" %%i in ("%ab%") do (
md %%i&cd %%i&&md %%j&cd %%j
copy /y "%ab%"
)
cd %path%
for /f "tokens=2,3 delims=\" %%m in ("%ac%") do (
md %%m&cd %%m&&md %%n&cd %%n
copy /y "%ac%"
)
pause
|
|
2008-4-14 15:31 |
|
|
flying008
中级用户
  
积分 245
发帖 103
注册 2006-6-30
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by zw19750516 at 2008-4-14 15:05:
xcopy /e命令是指复制文件夹里所有的内容啊(包括空文件夹),你测试了没有啊?
谢谢大大! 但偶的原文件路径比较深,而且系统文件非常多,像这样复制文件夹就带来了不需要的文件,不是偶想的指定文件的结果。谢谢……
Originally posted by zw19750516 at 2008-4-14 15:05:
The xcopy /e command means to copy all the contents in the folder (including empty folders). Have you tested it?
Thank you, sir! But my original file path is relatively deep, and there are very many system files. Copying the folder in this way brings unwanted files, which is not the result of the specified file I wanted. Thanks...
|
|
2008-4-14 17:25 |
|
|
bat-zw
金牌会员
      永远的学习者
积分 3105
发帖 1276
注册 2008-3-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
那只有先创建空文件夹了,代码也会多很多。
Then we have to create empty folders first, and the code will be much more.
|

批处理之家新域名:www.bathome.net |
|
2008-4-14 20:00 |
|
|
mkd
初级用户
 
积分 109
发帖 30
注册 2007-9-5
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by flying008 at 2008-4-14 11:13 AM:
abcd大大,你好!
运行这个bat时提示内部错误,请问如何修改后才能用这个bat来复制下面3个文件?
c:\IBM\123\456\789.nsf
c:\IBM\abc\cd.id
c:\Lotus ...
去除 /e
Originally posted by flying008 at 2008-4-14 11:13 AM:
Hello, Mr. abcd!
When running this bat, an internal error is prompted. May I ask how to modify it so that this bat can be used to copy the following 3 files?
c:\IBM\123\456\789.nsf
c:\IBM\abc\cd.id
c:\Lotus ...
Remove /e
|
|
2008-4-15 11:55 |
|