中国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-11 14:37
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Sort files by filename and put them into the corresponding folders
Printable Version  672 / 0
Floor1 gengster Posted 2009-03-14 00:32
新手上路 Posts 1 Credits 1
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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023