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-04 09:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » A new problem: it can run in XP—but why can't it run in 2K? why? View 942 Replies 13
Original Poster Posted 2007-04-21 09:59 ·  中国 江苏 苏州 电信
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
How can I use the contents of a TXT document as the name of a new folder
For example, on my computer under d: there is a 123.txt, and its contents are 120304. How can I create a new folder
named 120304??
Help!!
'Post #10': A new problem: it can run in XP—but why can't it run in 2K? why?

@echo off
set /a tm1=%date:~0,4%
set /a tm2=%date:~5,2%
set /a tm3=%date:~8,2%
set /a number=%tm1%*10000+%tm2%*100+%tm3%
if not exist D:\beifen.txt echo %number%>D:\beifen.txt
Changed to BAT format. When run in XP it generates beifen.txt with the current date as the content. But in 2K the content becomes echo is off
So depressing
Also, %tm2% and so on are octal. When it gets to month 08 or 09, or day 08 or 09, it won't work.. how do I change it
What I originally wanted was to create a TXT document with the current date as its content, and have it run in 2K...
...help

[ Last edited by 9389381 on 2007-4-22 at 05:43 PM ]
Floor 2 Posted 2007-04-21 13:29 ·  中国 江苏 苏州 电信
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
I need to use a for statement, but I can't get it to work
help
smile
Floor 3 Posted 2007-04-21 18:34 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
To 9389381:

First assign the contents of the 123.txt file to a variable, then create this folder.

For example:

@echo off
for /f "delims=" %%a in (123.txt) do set dirname=%%a
md "%dirname%"
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
9389381 +1 2007-04-22 11:37
Floor 4 Posted 2007-04-22 06:09 ·  中国 江苏 苏州 电信
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
I tried it, it works, thanks lx...
…^_^
Floor 5 Posted 2007-04-22 08:43 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
Brother lxmxn, can you explain why you don't just use "md %%a", but instead use "set dirname=%%a" and then "md "%dirname%""? Is there any difference between the two?
欢迎你到批处理爱好者联盟QQ群:18023953
Floor 6 Posted 2007-04-22 11:36 ·  中国 江苏 苏州 电信
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
Floor 7 Posted 2007-04-22 12:12 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by htysm at 2007-4-21 19:43:
Brother lxmxn, can you explain why you don't just use "md %%a", but instead use "set dirname=%%a" and then "md "%dirname%""? Is there any difference between the two?

First, so the OP can understand the idea; second, there may be a problem with spaces.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
9389381 +1 2007-04-23 03:20
Floor 8 Posted 2007-04-22 12:14 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Floor 9 Posted 2007-04-23 03:18 ·  中国 江苏 苏州 联通
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
Floor 10 Posted 2007-04-23 06:34 ·  中国 江苏 苏州 联通
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
@echo off
set /a tm1=%date:~0,4%
set /a tm2=%date:~5,2%
set /a tm3=%date:~8,2%
set /a number=%tm1%*10000+%tm2%*100+%tm3%
if not exist D:\beifen.txt echo %number%>D:\beifen.txt
Changed to BAT format. When run in XP it generates beifen.txt with the current date as the content. But in 2K the content becomes echo is off
So depressing
Also, %tm2% and so on are octal. When it gets to month 08 or 09, or day 08 or 09, it won't work.. how do I change it
What I originally wanted was to create a TXT document with the current date as its content, and have it run in 2K...
...help
Floor 11 Posted 2007-04-23 07:17 ·  中国 江苏 苏州 联通
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
I'm bumping bumping bumping bumping bumping bumping
Floor 12 Posted 2007-04-23 09:30 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Re 9389381:

This may be because the format of the %date% variable is different between 2000 and XP. You can run echo %date% under 2000 and XP respectively, then post the results here and see what is different about the format.

You can refer to this thread
http://www.cn-dos.net/forum/viewthread.php?tid=24829&fpage=1&highlight=2000%2Bver%2Blxmxn
Floor 13 Posted 2007-04-23 11:08 ·  中国 广东 广州 海珠区 电信
银牌会员
★★★
Credits 1,206
Posts 517
Joined 2007-03-25 01:18
19-year member
UID 82819
Gender Male
Status Offline
This problem has already been explained before...

The difference between 2000 and XP is:

2000: weekday month.
xp: month weekday.
知,不觉多。不知,乃求知
Floor 14 Posted 2007-04-25 12:03 ·  中国 江苏 苏州 电信
新手上路
Credits 18
Posts 8
Joined 2007-04-09 12:02
19-year member
UID 84495
Gender Male
Status Offline
I know there was a bit of a problem with that digit position,
thanks to all the experts
……^_^
Forum Jump: