![]() |
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-15 12:00 |
47,813 topics / 349,903 posts / today 1 new / 48,257 members |
| DOS疑难解答 & 问题讨论 (解答室) » How to respectively get the drive letter and path in a batch file? Thanks! |
| Printable Version 5,061 / 25 |
| Floor1 Sororal | Posted 2006-11-16 09:02 |
| 初级用户 Posts 13 Credits 35 | |
|
How to obtain this E:\Tools\pub3
And how to get E: and Tools\pub3 from it Thank you! |
|
| Floor2 0451lym | Posted 2006-11-16 12:51 |
| 高级用户 Posts 357 Credits 760 | |
|
There is a small command, it seems that DIRT.COM can meet your requirements!
|
|
| Floor3 lxmxn | Posted 2006-11-16 16:16 |
| 版主 Posts 4,938 Credits 11,386 | |
|
If it is a CMD batch file, you can try adding the following code in the file: |
|
| Floor4 Sororal | Posted 2006-11-16 22:10 |
| 初级用户 Posts 13 Credits 35 | |
Originally posted by lxmxn at 2006-11-16 16:16: |
|
| Floor5 Sororal | Posted 2006-11-16 22:21 |
| 初级用户 Posts 13 Credits 35 | |
Originally posted by 0451lym at 2006-11-16 12:51: Thanks, Brother 0451lym! I didn't find DIRT.COM through searching, Can you send one? Sororal@21cn.com Thanks a lot! |
|
| Floor6 Climbing | Posted 2006-11-16 22:46 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
If the batch file is in the search path (not in the current directory), I'm afraid brother lxmxn's solution is also invalid.
In a pure DOS environment, there is a command called fpath, which is used to find the path where the current command is located. But the result still needs to be further processed to separate the drive letter and path. http://nufans.net/clone/dostools/fpath.com |
|
| Floor7 Sororal | Posted 2006-11-16 23:10 |
| 初级用户 Posts 13 Credits 35 | |
Originally posted by Climbing at 2006-11-16 22:46: Thank you, Brother Xie! I still need you to teach me the specific usage. Thank you! |
|
| Floor8 DOSforever | Posted 2006-11-17 00:16 |
| 金牌会员 Posts 2,239 Credits 4,639 | |
|
If we don't consider complex situations, your this question can be said to be just a string processing problem. You can use the @instr variable function of 4DOS.
@instr[0,2,E:\Tools\pub3] Extract the string "E:" @instr[3,,E:\Tools\pub3] Extract the string "Tools\pub3" |
|
| Floor9 Sororal | Posted 2006-11-17 01:51 |
| 初级用户 Posts 13 Credits 35 | |
Originally posted by DOSforever at 2006-11-17 00:16: Thanks, Brother DOSforever! However, Book.bat may not necessarily be in E:\Tools\pub3, it may also be in other directories, so, E:\Tools\pub3 needs to be obtained first. |
|
| Floor10 DOSforever | Posted 2006-11-17 02:04 |
| 金牌会员 Posts 2,239 Credits 4,639 | |
|
If that's the case, then I still don't understand your requirement. What exactly are you trying to do? Do you mean to let a BATCH automatically find the path of Book.bat in the E:\Tools\pub3 or other directories?
|
|
| Floor11 0451lym | Posted 2006-11-17 04:48 |
| 高级用户 Posts 357 Credits 760 | |
Originally posted by Sororal at 2006-11-16 22:21: DIRT usage instructions are as follows: Dirt.COM FileName.Ext (Ver 1.15) (|)] HH:MM:SS] Note: The function of setting environment variables of this program cannot run normally in the following systems. winXP, win2000, and any system virtualized in Virtual PC Whether or not a file that meets the conditions is found, Dirt.COM will set the environment variable DirtRet when exiting: Fail means no file is found, and Success means a file is found. ===================================================== Ver 1.15 Update date: 2005-11-07 Upgrade instructions: (1) Correct the error in the previous version where it directly searched from the root directory when "without path and file name" was searched. (2) Add the automatic date calculation function to the original parameter YYYY-MM-DD]. Example: Rem Find all files modified yesterday dirt *.* /d:(-2) In the last relatively long example, because the function of "automatic date calculation" has been added now, it can be simplified as follows: @echo off rem ============================================ rem The function of this batch processing is to delete all files (including files in all subdirectories) in d:\datafile that were last modified 7 days ago (excluding 7 days) rem ============================================ attrib/s d:\datafile\*.* -h -r -s :Loop dirt.com /d:-(-7) d:\datafile\*.* /q if %DirtRet%==Fail goto end del %FPath%\%FName% goto Loop :end ===================================================== Ver 1.14 Update date: 2005-10-29 Upgrade instructions: (1) Correct the error that no file was found when searching in the root directory in the previous version. (2) Add the function of returning code exit to the function of . In this way, this function can be used in 2000 or xp. If the directory exists, return 1, If it does not exist, return 0. Example: Judge whether d:\aa exists. If it does not exist, create it and enter @echo off dirt /dir:d:\aa if errorlevel 1 goto exist echo make d:\aa md d:\aa :exist cd d:\aa ===================================================== Ver 1.13 Update date: 2005-10-14 Upgrade instructions: (1) Correct the wrong analysis of "*.*" in the previous version. (2) Add parameter Save the first 10 found files in the following environment variables O2E_DriverX, O2E_PathX, O2E_FNameX Save the drive letter, path, and file name respectively, where the last X is the serial number, Replaced by 0 to 9. If the searched is a directory, O2E_FNameX will not be set (3) Add parameter Among the found files or directories, find the one with the earliest or latest time, And save it in the following environment variables, FPath, FName furthest is to find the file or directory with the earliest time latest is the opposite (4) Add parameter The length of the main environment variable list of the Dos system is limited, so learn to clean up garbage. This function is to clear all environment variables generated by this program. (Note: The environment variables generated by this program cannot be cleared or modified by the Dos Set command Because the Set command does not support variable names with lowercase letters) Example: rem Find the file with the latest modification time under D: and display it dirt d:\*.* /time:latest echo %FPath%\%FName% rem Find the directory with the earliest creation time under D: and display it dirt d:\*.*\ /time:furthest echo %FPath% ===================================================== Ver 1.12 Update date: 2005-09-22 Upgrade instructions: (1) Correct some errors in "search path analysis". (2) Add the function of folder search. Support all parameters except But it finds the "creation time" of the directory. It is different from finding files (finding files is According to the "modification time" of the file), so when the directory is renamed, its creation time Will not change. In the quick mode , the full path including the folder to be searched will be written into the environment variable FPath, and FName will not be set The usage is: add a slash at the end of the path, and the specific method is as follows Example: dirt d:\ghost8\ /q Search for a folder named "ghost8" under drive D. If found, enter it @echo off rem Note that there must be \ after ghost8 rem Otherwise, it will become searching for files dirt d:\ghost8\ /q if == goto notexist cd %FPath% goto end :notexist echo No such directory found :end ===================================================== Ver 1.11 Update date: 2005-09-18 New function introduction: Judge whether a certain folder exists, and set the environment variable Dir: Exist means exists, NotExist means does not exist Example: Judge whether d:\aa exists. If it does not exist, create it and enter @echo off dirt /dir:d:\aa if == goto exist md d:\aa :exist cd d:\aa ===================================================== Ver 1.1 New function introduction: Whether or not a file that meets the conditions is found, Dirt.COM will set the environment variable DirtRet when exiting: Fail means no file is found, and Success means a file is found. In this version, the error that the parameter position cannot be changed arbitrarily in version 1.0 is also corrected. The function is the same as the /w of the dir command, and 5 file names are displayed per line. Enable quick mode. As long as one file that meets the conditions is found, the search will end immediately. And the file path and file name will be written into the environment variables FPath and FName respectively. In addition, this program is now compiled into a.com file, and its volume is half smaller than the original dirt.exe. ===================================================== Example: Find the Tc.exe file in drive D. If found, run it directly and open the file try.c in the root directory of drive D. If not found, display a prompt message. @echo off Dirt d:\tc.exe /Q if %DirtRet%==Fail goto NoFind d: cd %fpath% %fname% d:\try.c goto quit :NoFind echo. echo. echo Tc.exe not found in drive D :quit ===================================================== Function of Ver 1.0: YYYY-MM-DD] Specify the date, it must be of sufficient length, for example: /d:2004-05-01 cannot be written as /d:2004-5-1 The inside is only later or earlier than this date Such as: /d:-2004-05-01 Search for files before 2004-05-01 HH:MM:SS] Reference date format Time and date can be used together The maximum number of layers of subdirectories to search, the maximum is two digits (that is, 99), /L:0 does not search subdirectories The default is all layers ==================================================== Another example: @echo off rem ============================================ rem The function of this batch processing is to delete all files (including files in all subdirectories) in d:\datafile that were last modified 7 days ago (excluding 7 days) rem ============================================ rem ============================================ rem Get the date 7 days ago rem If today is August 25, the date 7 days ago is August 18 rem ============================================ GetInfo.COM /d:-7 set theDay=%year%-%mon%-%day% rem ============================================ rem This is to search for files modified 8 days ago (including 8 days) in D:\datafile rem That is, files modified on August 17 and before rem ============================================ attrib/s d:\datafile\*.* -h -r -s :Loop dirt.com /d:-%theDay% d:\datafile\*.* /q if %DirtRet%==Fail goto end del %FPath%\%FName% goto Loop :end Attachments Dirt.zip (15.92 KiB) |
|
| Floor12 0451lym | Posted 2006-11-17 04:52 |
| 高级用户 Posts 357 Credits 760 | |
|
Another small software by the same author is very practical, but unfortunately it cannot clear variables!
GetInfo.COM ver 1.2 /T Get current date and time. And It will modify follow environment variable. year,mon,day,wday hour,min,sec /C Get the first CDRom. And It will modify follow environment variable. CDRom /D It will modify follow environment variable. year,mon,day,wday /G:n,filename Get the String from the text file. The String must be short then 2048 Byte! It will modify follow environment variable. GetString,TheString /Cmp:x,y x=y return 0 x<y return 1 x>y return 2 ===================================================== Version 1.2 Update date:2005-10-16 Function introduction: Compare two numbers and return a value x=y return 0 x<y return 1 x>y return 2 Examples: Compare 12 and 13 and display the result @echo off getinfo /cmp:12,13 if errorlevel 2 goto big if errorlevel 1 goto small if errorlevel 0 goto equ goto end :big echo x bigger than y goto end :small echo x smaller than y goto end :equ echo x = y :end Judge whether today's date is the same as the set date @echo off getinfo /t set today=%Year%%Mon%%Day% getinfo /cmp:%today%,20051016 if errorlevel 2 goto big if errorlevel 1 goto small if errorlevel 0 goto equ goto end :big echo The set date has passed goto end :small echo The set date has not arrived yet goto end :equ echo Today is the set date :end ===================================================== Version 1.1 Update date:2005-06-24 Function introduction: Get the current system's date and time, and set the following environment variables. year: year mon: month day: day wday: day of the week (Sunday is 7) hour: hour min: minute sec: second Get the drive letter of the first CD-ROM, and set the environment variable CDRom. If there is a CD-ROM, set it to the drive letter of the CD-ROM. If there is no CD-ROM, set it to NoCDRom Calculate the current system's date with the specified days to get another date, and set the following environment variables. year: year mon: month day: day wday: day of the week (Sunday is 7) Examples: GetInfo.com /d:-1 Get yesterday's date GetInfo.com /d:+1 Get tomorrow's date Get the content of the nth line from the specified text file, and save the content in TheString. If the length of the string in this line is greater than 2048 characters, only 2048 characters will be taken. GetString=TRUE when successful, otherwise, GetString=FALSE Examples: GetInfo.com /g:5,D:\A.TXT Get the content of the 5th line in D:\A.TXT In addition, this program is now compiled into a .com file, and its size is half smaller than the original GetInfo.exe. Attachments Getinfo.zip (13.14 KiB) |
|
| Floor13 Sororal | Posted 2006-11-17 05:59 |
| 初级用户 Posts 13 Credits 35 | |
|
Thanks, brother 0451lym!
Study earnestly. |
|
| Floor14 lizaoyou | Posted 2007-01-30 12:42 |
| 中级用户 Posts 85 Credits 210 From 广东广州 | |
| Floor15 zybird | Posted 2007-02-01 01:44 |
| 中级用户 Posts 53 Credits 240 | |
|
dirt.com
Ver 1.16 (Just a little improvement, no new functions added) Update date: 2007-01-01 Upgrade instructions: When dirt is working, press Esc to exit immediately. In my actual use, many times when dirt is searching for files or directories, I suddenly think of a solution to the problem and want to immediately terminate dirt's current work, but using Ctrl+C or Ctrl+Break has no effect, which is very frustrating. In the Dos command line in Windows, you can terminate it at any time with Ctrl+Break, but it's not possible in pure Dos. So, I added the function to exit at any time to dirt.com. Download URL http://www.sendsong.cn/soft/ |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |