中国DOS联盟论坛

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-05 17:04
48,039 topics / 350,124 posts / today 2 new / 48,251 members
DOS批处理 & 脚本技术(批处理室) » Copy a file to many folders (with a pattern)
Printable Version  4,654 / 21
Floor1 beyoungse Posted 2007-01-04 00:52
中级用户 Posts 112 Credits 253
Copy the bak folder to folders such as a001, a002, ……, a009, ……, a010, ……, a100
Floor2 beyoungse Posted 2007-01-04 00:52
中级用户 Posts 112 Credits 253
Seek the advice of all experts
Floor3 namejm Posted 2007-01-04 00:57
荣誉版主 Posts 1,737 Credits 5,226 From 成都
```
@echo off
for /l %%i in (1,1,100) do call :copy_ %%i
goto :eof

:copy_
set num=00%1
set name=a%num:~-3%
copy bak %name%
goto :eof
```
Floor4 flamey Posted 2007-01-04 04:08
初级用户 Posts 74 Credits 152
There is a problem with the line "copy bak %name%" in the batch file upstairs. If there are no such folders in this directory originally, it will go wrong!
Floor5 namejm Posted 2007-01-04 04:16
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The owner of the post did not specifically state whether these folders exist. According to the general understanding, they are default to exist; if they do not exist, then it can only be blamed on the owner of the post for not making it clear; for ambiguous questions, no one, no matter who, can solve them perfectly.
Floor6 beyoungse Posted 2007-01-04 23:56
中级用户 Posts 112 Credits 253
I'm sorry, I'm a newbie. I want to save some trouble in actual application, so I come to ask the experts.

I didn't think too much about my question, sorry
Floor7 beyoungse Posted 2007-01-05 00:09
中级用户 Posts 112 Credits 253
```batch
@echo off
for /l %%i in (1,1,100) do call :copy_ %%i
goto :eof

:copy_
set num=00%1
set name=a%num:~-3%
xcopy bak "%name%" /e /i
goto :eof
```

我试过了,可是目标都成了文件,而不是文件夹

我的目的是把BAK这个文件夹拷贝到已经存在的文件夹中(a001,a002 ……a100这些目录是已经存在的文件夹)
Floor8 namejm Posted 2007-01-05 01:49
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Hehe, didn't read the question carefully, thought bak was a file, made a mistake. To copy a folder, you should replace copy with xcopy and add appropriate parameters.
Floor9 beyoungse Posted 2007-01-05 04:35
中级用户 Posts 112 Credits 253
Copy the "Documents and Settings" file to the folders A001, A002, A003...A110 folders

[ Last edited by beyoungse on 2007-1-7 at 12:33 PM ]
Floor10 beyoungse Posted 2007-01-07 12:35
中级用户 Posts 112 Credits 253
Copy the "Documents and Settings" file to the folders A001, A002, A003……A110Folder
Floor11 dikex Posted 2007-01-07 12:48
高级用户 Posts 366 Credits 788
The NTUSER and NTUSER.DAT files in the Documents and Settings\%username%\ folder are registry - related files, and they cannot be normally copied.
Floor12 beyoungse Posted 2007-01-07 12:55
中级用户 Posts 112 Credits 253
This folder was created by myself, and it only contains a few files created by myself. Boss, help me.
Floor13 beyoungse Posted 2007-01-07 12:56
中级用户 Posts 112 Credits 253
My purpose is to place the user's desktop on a file server, and the user's system is read-only
Floor14 dikex Posted 2007-01-07 13:02
高级用户 Posts 366 Credits 788
Just enclose the path with "" when copying, and it can be copied normally
Floor15 beyoungse Posted 2007-01-07 13:10
中级用户 Posts 112 Credits 253
Can you help write it? Operating in the current directory, no need to write the path, right?

I used the above batch processing,
@echo off
for /l %%i in (1,1,100) do call :copy_ %%i
goto :eof

:copy_
set num=00%1
set name=a%num:~-3%
copy Documents and Settings %name%
goto :eof
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023