|
bakeyhe
新手上路

积分 10
发帖 4
注册 2006-11-3
状态 离线
|
『楼 主』:
请问怎样实现将文件按照文本文件内容存储?
使用 LLM 解释/回答一下
新人第一帖,希望大家支持
刚刚进入的批处理操作的美好境界,好多东西只靠自己的水平还不能实现,所以特来求助各位
具体是这样的:
某个文件夹里有很多文件,并且这些文件都存储在不同的子目录内
001_aa
001_bb
002
003
等等
同时这个文件夹里有一个txt文件,内容如下
001,名称1,分类1
002,名称2,分类2
003,名称3,分类3
我现在想把所有的文件按照这个txt文件的内容来重命名以及重新存储。
比如,"001_aa"这个文件,按照txt的要求,就改名为“名称1_aa”,并且在根目录下建立 “分类1”这个目录,在分类1下建立 “名称1”这个目录,把所有001_*的文件都复制到名称1这个新建的目录下。
不知道该怎么解决,希望能够得到各位的帮助,感谢各位!!
Newcomer's first post, hope everyone supports.
Just entered the wonderful realm of batch processing operations, many things can't be realized only by my own level, so I come here to ask for help from everyone.
Specifically like this:
There are many files in a certain folder, and these files are all stored in different subdirectories
001_aa
001_bb
002
003
and so on.
At the same time, there is a txt file in this folder, the content is as follows
001, Name 1, Category 1
002, Name 2, Category 2
003, Name 3, Category 3
I now want to rename and re - store all files according to the content of this txt file.
For example, the file "001_aa" is renamed to "Name 1_aa" according to the requirements of txt, and a directory "Category 1" is established in the root directory, a directory "Name 1" is established under Category 1, and all files with 001_* are copied to the newly - created directory Name 1.
Don't know how to solve it, hope to get everyone's help, thank everyone!
|
|
2006-11-3 01:46 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
我很想帮你一下,但是你的描述我看不太明白,这也可能是到现在没有别的朋友回帖的原因吧。
你用 tree /f 列一下目录贴上来,001_aa、001_bb ...最终要求改成什么样的文件名你详细说一下。
I really want to help you, but I can't understand your description clearly. This might be the reason why no other friends have replied so far. Please list the directory with tree /f and post it, and also tell me in detail what kind of file names you want to change the final 001_aa, 001_bb... into.
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-3 05:58 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
同楼上,没有看明白你到底想达到什么样的木的
Same as the person above, I didn't understand exactly what kind of goal you are trying to achieve.
|
|
2006-11-3 07:10 |
|
|
bakeyhe
新手上路

积分 10
发帖 4
注册 2006-11-3
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
艾,果然我的描述能力很差……
我贴出目录树来~
├─new
│ ├─3班
│ │ └─阿四
│ │ ├─物理
│ │ │ 阿四_物理
│ │ │
│ │ ├─数学
│ │ │ 阿四_数学
│ │ │
│ │ └─化学
│ │ 阿四_化学
│ │
│ ├─2班
│ │ └─阿三
│ │ ├─物理
│ │ │ 阿三_物理
│ │ │
│ │ ├─数学
│ │ │ 阿三_数学
│ │ │
│ │ └─化学
│ │ 阿三_化学
│ │
│ └─1班
│ ├─阿二
│ │ ├─物理
│ │ │ 阿二_物理
│ │ │
│ │ ├─数学
│ │ │ 阿二_数学
│ │ │
│ │ └─化学
│ │ 阿二_化学
│ │
│ └─阿一
│ ├─物理
│ │ 阿一_物理
│ │
│ ├─数学
│ │ 阿一_数学
│ │
│ └─化学
│ 阿一_化学
│
└─old
│ a.txt
│
├─数学
│ 001
│ 002
│ 003
│ 004
│
├─化学
│ 001
│ 002
│ 003
│ 004
│
└─物理
001
002
003
004
其中,a.txt的内容如下
001,阿一,1班
002,阿二,1班
003,阿三,2班
004,阿四,3班
我就是希望能把old中的文件,按照 a.txt 的要求改名,并且新建文件夹,然后变成 new 这样的保存方式。
不知道这下有没有说清楚,呵呵~
Ai, my description ability is really poor...
I post the directory tree~
├─new
│ ├─Class 3
│ │ └─Ah Si
│ │ ├─Physics
│ │ │ Ah Si_Physics
│ │ │
│ │ ├─Mathematics
│ │ │ Ah Si_Mathematics
│ │ │
│ │ └─Chemistry
│ │ Ah Si_Chemistry
│ │
│ ├─Class 2
│ │ └─Ah San
│ │ ├─Physics
│ │ │ Ah San_Physics
│ │ │
│ │ ├─Mathematics
│ │ │ Ah San_Mathematics
│ │ │
│ │ └─Chemistry
│ │ Ah San_Chemistry
│ │
│ └─Class 1
│ ├─Ah Er
│ │ ├─Physics
│ │ │ Ah Er_Physics
│ │ │
│ │ ├─Mathematics
│ │ │ Ah Er_Mathematics
│ │ │
│ │ └─Chemistry
│ │ Ah Er_Chemistry
│ │
│ └─Ah Yi
│ ├─Physics
│ │ Ah Yi_Physics
│ │
│ ├─Mathematics
│ │ Ah Yi_Mathematics
│ │
│ └─Chemistry
│ Ah Yi_Chemistry
│
└─old
│ a.txt
│
├─Mathematics
│ 001
│ 002
│ 003
│ 004
│
├─Chemistry
│ 001
│ 002
│ 003
│ 004
│
└─Physics
001
002
003
004
Among them, the content of a.txt is as follows
001, Ah Yi, Class 1
002, Ah Er, Class 1
003, Ah San, Class 2
004, Ah Si, Class 3
I just hope to rename the files in old according to the requirements of a.txt, and create new folders, and then change to the saving method like new.
I don't know if this is clear now, heh heh~
|
|
2006-11-3 22:05 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
总算明白了,目录结构有些复杂,详细测试了一下没有问题了。
如果还有其他科目目录自己添加一下。
- @echo off
- md new
- for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
- md new\%%c\%%b
- for %%i in (数学 化学 物理) do (
- echo F|xcopy /y %%i\%%a new\%%c\%%b\%%i\%%b_%%i
- )
- )
无奈何发表于 2006-11-03 11:11
Finally, I understand. The directory structure is a bit complicated, but after detailed testing, there are no problems.
If there are other subject directories, please add them yourself.
- @echo off
- md new
- for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
- md new\%%c\%%b
- for %%i in (Mathematics Chemistry Physics) do (
- echo F|xcopy /y %%i\%%a new\%%c\%%b\%%i\%%b_%%i
- )
- )
Helplessly posted on November 3, 2006 at 11:11
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-3 23:15 |
|
|
bakeyhe
新手上路

积分 10
发帖 4
注册 2006-11-3
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
感谢版主的帮助
可是还是有点小问题,如果原始的文件夹里的文件后缀名不同,那么这个该怎么做啊?
版主的代码似乎没有考虑到后缀名的问题哦
Thanks to the moderator's help
But there is still a small problem. If the file extensions in the original folder are different, then how should this be done?
It seems that the moderator's code did not consider the issue of file extensions哦
|
|
2006-11-4 02:43 |
|
|
无奈何
荣誉版主
      
积分 1338
发帖 356
注册 2005-7-15
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
这是按你四楼提供的例子写的。如此只需更改第 6 行为:
echo F|xcopy /y %%i\%%a* new\%%c\%%b\%%i\%%b_%%i
即可。
This is written according to the example you provided on the fourth floor. So just change line 6 to:
echo F|xcopy /y %%i\%%a* new\%%c\%%b\%%i\%%b_%%i
|

☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul
|
|
2006-11-4 04:15 |
|
|
bakeyhe
新手上路

积分 10
发帖 4
注册 2006-11-3
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
感谢!
但是我改成这样才可以正常运行了
echo F|xcopy /y %%i\%%a.* new\%%c\%%b\%%i\%%b_%%i.*
嘿嘿
对了,我对这行有点不太明白……
for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
我正在看坛子上的教程,不过也希望哪位能给我稍稍讲解一下拉~
再次感谢!
补充一下~怪不得我刚才运行不成……
for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
原来是这个逗号…………真是欲哭无泪啊~
哈哈
不过现在找到原因了
继续研究ing
Last edited by bakeyhe on 2006-11-4 at 05:04 AM ]
Thanks!
But I can run it normally only after changing it like this
echo F|xcopy /y %%i\%%a.* new\%%c\%%b\%%i\%%b_%%i.*
Hehe
By the way, I don't quite understand this line...
for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
I'm reading the tutorials on the forum, but I also hope someone can give me a little explanation~
Thanks again!
Supplement~ No wonder it didn't run just now...
for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
It was this comma... really in tears~
Haha
But now I found the reason
Continuing to study ing
Last edited by bakeyhe on 2006-11-4 at 05:04 AM ]
|
|
2006-11-4 04:39 |
|
|
hxuan999
中级用户
   DOS之日
积分 337
发帖 161
注册 2006-11-4
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
md new\%%c\%%b
其中 delims=,是分隔符集。这里也就是“,”号。
tokens=1,2,3可以是tokens=x,y,m-n的形势。x,y可以指定为数字,m-n为一个范围。也就是把a.txt中的一行用“,”号分隔后,把指定位置的内容传给l了后面的%%a,%%b,%%c...等变量。
当然这里不能超过26个字母。如:
for /f "tokens=2,4,5-7,8* delims=," %%a in (tt.txt) do (
echo %%a %%b %%c %%d %%e %%f %%g)
在tt.txt中内容有:
aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk
11,22,33,44,55,66,77,88,99,00,1010
那么运行结果为:
bb dd ee ff gg hh ii,jj,kk
22 44 55 66 77 88 99,00,1010
“*”是把8后所有的内容都给了%%g。
5-7也就是5,6,7是一样的。
我也是刚学,请指教。
for /f "tokens=1,2,3 delims=," %%a in (a.txt) do (
md new\%%c\%%b
Among them, delims=,is the delimiter set. Here it is the "," character.
tokens=1,2,3 can be in the form of tokens=x,y,m-n. x,y can be specified as numbers, and m-n is a range. That is, after splitting a line in a.txt with the "," character, the content of the specified position is passed to variables like %%a,%%b,%%c... later.
Of course, here it cannot exceed 26 letters. For example:
for /f "tokens=2,4,5-7,8* delims=," %%a in (tt.txt) do (
echo %%a %%b %%c %%d %%e %%f %%g)
In tt.txt, the content is:
aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk
11,22,33,44,55,66,77,88,99,00,1010
Then the running result is:
bb dd ee ff gg hh ii,jj,kk
22 44 55 66 77 88 99,00,1010
"*" is to give all the content after 8 to %%g.
5-7 means 5, 6, 7 are the same.
I'm also just learning, please give advice.
|
|
2006-11-4 06:24 |
|
|