![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-08 03:42 |
48,041 topics / 350,128 posts / today 3 new / 48,253 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved] Copying specified N files with relative paths of folders |
| Printable Version 2,247 / 15 |
| Floor1 flying008 | Posted 2008-04-11 17:05 |
| 中级用户 Posts 103 Credits 245 | |
|
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 ] |
|
| Floor2 tvzml | Posted 2008-04-11 17:18 |
| 初级用户 Posts 67 Credits 157 | |
|
This is simple, the following line meets your requirement.
xcopy /d/r/y/e/h %cd% E:\bak\ |
|
| Floor3 flying008 | Posted 2008-04-11 17:24 |
| 中级用户 Posts 103 Credits 245 | |
Originally posted by tvzml at 2008-4-11 17:18: 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 ] |
|
| Floor4 flying008 | Posted 2008-04-12 12:28 |
| 中级用户 Posts 103 Credits 245 | |
|
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!
|
|
| Floor5 bat-zw | Posted 2008-04-12 12:40 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
@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 ] |
|
| Floor6 flying008 | Posted 2008-04-12 15:15 |
| 中级用户 Posts 103 Credits 245 | |
|
@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 ] |
|
| Floor7 abcd | Posted 2008-04-12 15:37 |
| 银牌会员 Posts 739 Credits 1,436 | |
|
```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 ] |
|
| Floor8 flying008 | Posted 2008-04-14 11:13 |
| 中级用户 Posts 103 Credits 245 | |
|
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 ] |
|
| Floor9 bat-zw | Posted 2008-04-14 12:48 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
```
@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 ] |
|
| Floor10 flying008 | Posted 2008-04-14 13:35 |
| 中级用户 Posts 103 Credits 245 | |
Originally posted by zw19750516 at 2008-4-14 12:48: 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 ] |
|
| Floor11 bat-zw | Posted 2008-04-14 15:05 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
The xcopy /e command means to copy all the contents in the folder (including empty folders). Did you test it?
|
|
| Floor12 moniuming | Posted 2008-04-14 15:31 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
There is no more foolish way than this, but it must be achievable (if the number of directory levels is different, make corresponding changes):
|
|
| Floor13 flying008 | Posted 2008-04-14 17:25 |
| 中级用户 Posts 103 Credits 245 | |
Originally posted by zw19750516 at 2008-4-14 15:05: 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... |
|
| Floor14 bat-zw | Posted 2008-04-14 20:00 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Then we have to create empty folders first, and the code will be much more.
|
|
| Floor15 mkd | Posted 2008-04-15 11:55 |
| 初级用户 Posts 30 Credits 109 | |
Originally posted by flying008 at 2008-4-14 11:13 AM: Remove /e |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |