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-09 09:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Create folders in batches based on filenames, and put the files into them View 730 Replies 5
Original Poster Posted 2008-08-07 10:15 ·  中国 云南 曲靖 电信
新手上路
Credits 8
Posts 3
Joined 2008-08-07 09:29
18-year member
UID 122875
Gender Male
Status Offline
There are several hundred files in one directory. Their filenames are similar, all like “20080102-XXX”, etc. Now I want to create corresponding subfolders in a format like “20080102”, etc., and put all files beginning with 20080102 into the matching folder. What should I do?
For example, if the folder contains the file: 20080103-Zhang Sanfeng-file
then create the subfolder 20080103, and put the above file into it
Similarly, put 20080506-Sun Xiaoyi-report materials into 20080506

Please don't hesitate to advise, thanks!
Floor 2 Posted 2008-08-07 13:07 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Floor 3 Posted 2008-08-09 10:24 ·  中国 云南 曲靖 电信
新手上路
Credits 8
Posts 3
Joined 2008-08-07 09:29
18-year member
UID 122875
Gender Male
Status Offline
Originally posted by huahua0919 at 2008-8-7 01:07 PM:

@echo off
for /f "tokens=1* delims=-" %%i in ('dir/a-d/b^|findstr "^2008.*"') do (
md %%i 2>nul
copy "%%i-%%j" %%i /y
)
pause



Using the above command I can get the “20080506” folder, but what I want is the “20080506-Sun Xiaoyi” folder
Floor 4 Posted 2008-08-09 10:37 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline

then create the subfolder 20080103

Wasn't that what you yourself said?
Floor 5 Posted 2008-08-09 10:42 ·  中国 江苏 苏州 吴江区 电信
银牌会员
★★★
Credits 1,608
Posts 780
Joined 2007-10-07 10:19
18-year member
UID 99089
Gender Male
Status Offline
Floor 6 Posted 2008-08-09 11:07 ·  中国 云南 曲靖 电信
新手上路
Credits 8
Posts 3
Joined 2008-08-07 09:29
18-year member
UID 122875
Gender Male
Status Offline
Oh, thanks, I said it wrong
Forum Jump: