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-06-27 20:08
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » Seek help, create a folder in the last drive letter View 5,055 Replies 27
Original Poster Posted 2006-09-23 07:03 ·  中国 浙江 台州 电信
初级用户
Credits 54
Posts 18
Joined 2006-08-26 13:12
19-year member
UID 61314
Status Offline
Different machines have different partitions. How can I create a directory in the last partition?
Floor 2 Posted 2006-09-24 04:38 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
Does the thread starter have any good implementation ideas?

To be compatible with pure DOS and DOS under Windows, use a for loop to enumerate all drives and find the last writable drive? To be compatible with the pure DOS environment, external interpreted scripts like VbScript cannot be used, only DOS internal commands can be used.

1. Enumerate all drive letters using the DOS internal command for
2. Test if the enumerated drive letter exists using if
3. If it exists, create the predetermined directory name on that drive letter

I've done it for you, but I most hope you do it for fun, and then your DOS skills will improve quickly~ : )

Hope the thread starter posts your implementation process. It's a very fun thing to figure it out~ : )


You can refer to this post for the enumeration and application methods of for:
=============================================
Batch script to delete all partition default shares
http://www.cn-dos.net/forum/viewthread.php?tid=21133&fpage=4
=============================================

Take a look at the application of if. Look at the prompt and help of IF /? ~ : )

Knowledge all comes to breakthroughs when encountering unsolvable problems~ : )
Hope the thread starter makes it soon~ : )
Wait for the thread starter to talk about the discovery and learning feelings and wonderful fragments to share with everyone~ : )
Floor 3 Posted 2006-09-25 04:36 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline
You can try this:

@echo off
setlocal enabledelayedexpansion
for /f "delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
set var=%%i
set drives=!var:~-2!
md !drives!\lxmxn
)

The "lxmxn" in the third last line above is the folder name I defined myself, and you can change it to the directory name you want to name by yourself.
Floor 4 Posted 2006-09-26 03:53 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
"Help, create a folder in the last drive letter"

After execution, I found that it created the lxmxn directory on the C drive : )
I really admire Brother Lxmxn's use of fsutil fsinfo drives, all the drives came out at once, super cool : )
Floor 5 Posted 2006-09-26 05:19 ·  IANA 局域网IP(Private-Use)
初级用户
Credits 70
Posts 27
Joined 2006-09-19 19:23
19-year member
UID 63080
Gender Male
From 河南
Status Offline
Is everyone not considering what if the last drive letter is for a CD - ROM?

Result of floor 3

E:\>for /F "delims=\" %i in ('fsutil fsinfo drives|find /v ""') do (
set var=%i
set drives=!var:~-2!
md !drives!\lxmxn
)
find: invalid predicate `'


[ Last edited by uime on 2006-9-26 at 05:37 ]
Floor 6 Posted 2006-09-26 06:20 ·  中国 北京 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
I've been waiting for the楼主 to ask a question and then saw the inspiration from the 2nd and 3rd floors to write it myself. The memory and understanding of what others wrote and what I wrote are different. As a result, the楼主 disappeared...

Make the drive letters go in reverse order, and the first writable drive tested will definitely be the last writable drive letter.



@REM The name redtek is the directory name you want to create

@REM CreateFile.Bat:
@REM ==========================================

@ECHO off

FOR %%c in (Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
MD %%c:\Redtek
GOTO :EOF
)
)


Floor 7 Posted 2006-09-26 18:54 ·  IANA 局域网IP(Private-Use)
初级用户
Credits 70
Posts 27
Joined 2006-09-19 19:23
19-year member
UID 63080
Gender Male
From 河南
Status Offline
Originally posted by redtek at 2006-9-26 06:20:
Been waiting for the LZ to ask a question, then see the inspiration from floor 2 and 3 to write it out myself.
The memory and understanding of what others have written out versus what I write out are different.
In the end, the LZ disappeared...


Let the drive letter be...

If there is a CD in the optical drive, this will not execute.
If there is a substituted virtual drive, this will be created in the virtual directory.

[ Last edited by uime on 2006-9-26 at 19:18 ]
Floor 8 Posted 2006-09-27 05:22 ·  中国 浙江 台州 椒江区 电信
初级用户
Credits 54
Posts 18
Joined 2006-08-26 13:12
19-year member
UID 61314
Status Offline
Originally posted by redtek at 2006-9-26 06:20:
Been waiting for the original poster to ask a question and then see the inspiration from floors 2 and 3 to write it out myself,
The memory and understanding of content written by others and what I write are different,
As a result, the original poster disappeared...


Let the drive letter be...


Just starting to learn, looked at the help, and there is something unclear
What does goto :eof mean? goto :eof seems to be jumping to the label :eof to execute, but this label is not found in the entire processing.
Floor 9 Posted 2006-09-27 05:22 ·  中国 浙江 台州 椒江区 电信
初级用户
Credits 54
Posts 18
Joined 2006-08-26 13:12
19-year member
UID 61314
Status Offline
Originally posted by redtek at 2006-9-26 06:20:
Been waiting for the original poster to ask a question and then see the inspiration from floors 2 and 3 to write it out myself,
The memory and understanding of what others have written out versus what I write out are different,
As a result, the original poster disappeared...


Let the drive letter...


Just starting to learn, looked at the help, there is something unclear
goto :eof
What does it mean? goto :eof seems to be jumping to the label :eof to execute, but I didn't find this label in the entire process.
Floor 10 Posted 2006-09-28 04:09 ·  中国 安徽 宿州 泗县 电信
银牌会员
★★★
Credits 1,339
Posts 595
Joined 2004-05-26 00:00
22-year member
UID 25306
Gender Male
From 安徽 宿州
Status Offline
What if the last drive letter in pure DOS is a RAM drive?
Floor 11 Posted 2006-09-28 06:19 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
What if the power is suddenly cut off when the directory is being built?

What if the last disk happens to be a disk of another host on the mapped network?

What if there is a program in memory resident monitoring the system and not allowing writing to the last disk?

What if the last disk is a USB flash drive and write protection is enabled?

What if a once - in - a - hundred - year system bug is encountered during the operation?

Hahaha...
Floor 12 Posted 2006-09-28 08:09 ·  中国 浙江 衢州 电信
银牌会员
★★★
Credits 1,270
Posts 548
Joined 2004-05-31 00:00
22-year member
UID 25754
Gender Male
Status Offline
for and if are powerful.
Floor 13 Posted 2006-09-28 10:33 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by redtek at 2006-9-26 06:20:
@REM The name redtek is the directory name you want to create

@REM CreateFile.Bat:
@REM ==========================================

@ECHO off

FOR %%c in (Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
MD %%c:\Redtek
GOTO :EOF
)
)


  There is a problem with this code. If the last existing drive letter is that of a CD-ROM drive, then it won't be able to create it. According to the original poster's statement, it should be finding the last writable drive. Then it should be written as

@ECHO off

FOR %%c in (Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
MD %%c:\Redtek 2>nul && GOTO :EOF
)
)
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
zhclvip +2 2007-02-02 08:51
andysky +2 2007-03-15 03:32
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 14 Posted 2006-09-28 21:28 ·  中国 福建 南平 电信
初级用户
Credits 197
Posts 33
Joined 2003-07-24 00:00
22-year member
UID 7424
Gender Male
Status Offline
What is said above can only be on the partition formats of FAT16 FAT32. In pure DOS, if the hard disk is all in NTFS format or the last partition is in NTFS format, it won't work.

[ Last edited by Jnwei1202 on 2006-9-28 at 21:36 ]
Floor 15 Posted 2006-09-28 22:04 ·  中国 江苏 苏州 电信
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Then load the NTFS driver first
Forum Jump: