中国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-09-29 22:58
47,813 topics / 349,918 posts / today 0 new / 48,278 members
DOS批处理 & 脚本技术(批处理室) » [Ask] How to get the last part of the file name in the absolute path? [Solved]
Printable Version  7,155 / 25
Floor16 lxmxn Posted 2006-10-21 02:54
版主 Posts 4,938 Credits 11,386

Brother namajm, is the code in F11 a test error code or a correct code?

I tested here and it didn't pass. It shows "ab" instead of the "ab c" we want. I don't know why.
Floor17 namejm Posted 2006-10-21 06:15
荣誉版主 Posts 1,737 Credits 5,226 From 成都
I'm sorry, the example I gave was to show that the code couldn't correctly get the folder name of the specified level in the path with spaces. I didn't make it clear at that time, but now it's commented properly.
Floor18 namejm Posted 2006-10-21 06:17
荣誉版主 Posts 1,737 Credits 5,226 From 成都
The code in 14F is really remarkable. It uses a relatively obscure shift, which is quite skillful. It might be the most general-purpose one.
Floor19 lxmxn Posted 2006-10-21 07:03
版主 Posts 4,938 Credits 11,386

  Hehe...

  I've been thinking about this question all the time:

  Why does the code on floor 11 not work, but the code on floor 14 does? Is it just the role of this shift? I still don't understand why we need to loop 4 times.
Floor20 3742668 Posted 2006-10-21 07:35
荣誉版主 Posts 718 Credits 2,013
Take a look at <Help and Support> more. Different combinations have different flavors, which is also one of the reasons for the existence of scripts:


Changing the final cd to echo allows displaying level by level. The several methods are used in different situations, and as for which is better or worse, that is a matter of personal opinion.
Floor21 namejm Posted 2006-10-21 08:39
荣誉版主 Posts 1,737 Credits 5,226 From 成都
I found the sentence "echo %str:\= && 2>nul cd %". I can't figure out how to write to remove the last few content separated by \. I hope 3742668 can explain it.

In addition, when extracting the folder name from "echo %str:\= && 2>nul cd %", the last character is a space. There is no this problem when extracting the file name. It can be changed to "echo %str:\=&& 2>nul cd %" (note: there is a space before && in the two statements and no space in one).
Floor22 pengfei Posted 2006-10-21 08:43
银牌会员 Posts 485 Credits 1,218 From 湖南.娄底
Originally posted by 3742668 at 2006-10-21 07:35:
Take a look at the <Help and Support> more.
Different combinations have different flavors, which is also one of the reasons why scripts exist:
Several methods are used in different situations, and as for which is better or worse, that is a matter of personal opinion.


Agree, there are various ways to solve problems, just see how you use them.
Floor23 3742668 Posted 2006-10-21 09:00
荣誉版主 Posts 718 Credits 2,013
Originally posted by namejm at 2006-10-21 08:39:
  I found that in the sentence "echo %str:\= && 2>nul cd %", replacing "cd" with any command can execute correctly. I can't figure out the writing method of removing the last few \-separated contents. I still need to ask 37426...

I remember that a similar method was used in that post discussing encryption and decryption.
The principle is very simple, for example:

Reference: Non-compiled Batch Processing Encryption Scheme and Code of 11F scheme.
In addition, in fact, there is still a small problem with the last method. When getting the final file name, a prompt like "ECHO is on" might be displayed. To save code quantity, it was not processed.
Floor24 uemuem Posted 2006-10-24 03:32
初级用户 Posts 68 Credits 153 From 上海
Originally posted by 3742668 at 2006-10-21 09:00:

I remember that a similar method was used in that post discussing encryption and decryption.
The principle is very simple, for example:
Floor25 namejm Posted 2006-10-24 06:39
荣誉版主 Posts 1,737 Credits 5,226 From 成都
May I ask under what circumstances the prompt "ECHO is in the on/off state" appears? Please send out the test path for me to take a look. It is estimated that changing echo %str:\= && 2>nul cd % to echo. %str:\=&& 2>nul cd % will work (note that there is a dot after echo).
Floor26 cl87388881 Posted 2006-10-24 21:58
初级用户 Posts 22 Credits 46
Well, strong! Worth learning~!
Prev  1 2
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023