China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 15:31
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Sort files by filename and put them into the corresponding folders View 674 Replies 0
Original Poster Posted 2009-03-14 00:32 ·  中国 福建 厦门 电信
新手上路
Credits 1
Posts 1
Joined 2009-03-12 23:47
17-year member
UID 141169
Gender Male
Status Offline
Sorry for registering and then posting a question right away.
I’ve studied quite a few posts by the veterans in the batch file section. Mainly, an office clerk colleague wants to solve a problem: every day there are quite a lot of files to handle, and after processing them they need to be archived into their corresponding folders. Since there are quite a few categories, it gets rather tedious over the course of a day, so I want to make a batch file to solve this directly. For example: fax**.doc should be put into the “Fax” folder under “Office”, phone record**.doc should be put into the “Phone Records” folder under “Office”, sales**.doc should be put into the “Sales Department” folder, purchase**.doc should be put into the “Purchasing Department” folder. . . . . .

A few notes about the situation: (1) each Word file name already begins with a fixed marker to distinguish it; (2) the corresponding folder for each type of file has already been determined, but new categories may be added; (3) if no corresponding folder is found, create it directly.

After studying posts such as “[fixed] Move files into folders containing characters from the filename?” and “According to the filename, batch-create folders and put files into them”, I got some ideas, and solved the problem in a rather embarrassing way, but I feel it doesn’t make use of the advantages of batch files at all, so I’d like to ask the experts again whether there are other approaches, and if possible provide some code so I can learn.
Idea 1: (the one I used, sweat) use for to traverse the temporary folder, judge each category separately, and move them separately into the corresponding folders.
Idea 2: create a text file, with each line in a format like “fax-Office/Fax” or “fax Office/Fax”, then use for in the temporary folder to traverse the files, and for those whose first few characters of the filename match, put them into the corresponding folder according to the folder name after it; if there is no corresponding folder, create it directly.
Forum Jump: