![]() |
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-10 16:59 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » How to add the full path to the file names in the dir result |
| Printable Version 5,539 / 17 |
| Floor1 onlykier | Posted 2006-11-07 23:22 |
| 初级用户 Posts 23 Credits 50 | |
|
Suppose there are subdirectories under a directory, and there are subdirectories under the subdirectories. Use the following command
dir /s /a-d /tc|sort|find "-"|find /v "Sequence" The result is similar to the following 2006-10-01 19:49 123,392 asdfasdfasd060921-060927.xls 2006-10-01 19:49 123,904 asdfasdfasd060914-060920.xls 2006-10-01 19:49 161,280 asdfasdfasd060831-060906.xls 2006-10-01 19:49 167,936 asdfasdfasd060907-060913.xls 2006-10-07 19:08 160,768 asdfasdfasd060824-060830.xls 2006-10-07 19:13 124,928 asdfasdfasd060928-061004.xls 2006-10-12 00:17 124,416 asdfasdfasd061005-061011.xls 2006-10-19 08:18 124,928 asdfasdfasd061012-061018.xls 2006-10-26 12:22 124,928 asdfasdfasd061019-061025.xls I want to display the directory name of the file before the file name, and the result is like this. How to do it? 2006-10-01 19:49 123,392 d:\x1\asdfasdfasd060921-060927.xls 2006-10-01 19:49 123,904 d:\x2\asdfasdfasd060914-060920.xls 2006-10-01 19:49 161,280 d:\x2\1\asdfasdfasd060831-060906.xls 2006-10-01 19:49 167,936 d:\x2\2\asdfasdfasd060907-060913.xls 2006-10-07 19:08 160,768 d:\x2\3\asdfasdfasd060824-060830.xls 2006-10-07 19:13 124,928 d:\x4\asdfasdfasd060928-061004.xls 2006-10-12 00:17 124,416 d:\x5\asdfasdfasd061005-061011.xls 2006-10-19 08:18 124,928 d:\x4\1\asdfasdfasd061012-061018.xls 2006-10-26 12:22 124,928 d:\x4\3\asdfasdfasd061019-061025.xls ──────────────── Moderation Record ──────────────── Performed by: namejm Original title: Ask a dir question Modified title: How to add the full path to the file name in the dir result Explanation: The title is too vague, which is not convenient for forum search and management. Three days after this prompt is posted, the original poster has not modified the title. Now, the title is forcibly modified by me, and 2 points of points are deducted from the original poster. ──────────────── Moderation Record ──────────────── [ Last edited by namejm on 2007-2-3 at 08:38 PM ] |
|
| Floor2 不得不爱 | Posted 2006-11-07 23:27 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
dir/s/b
Are time and size necessary? [ Last edited by 不得不爱 on 2006-11-7 at 11:29 AM ] |
|
| Floor3 onlykier | Posted 2006-11-07 23:33 |
| 初级用户 Posts 23 Credits 50 | |
|
Dates and file names are needed, others are optional
|
|
| Floor4 onlykier | Posted 2006-11-07 23:35 |
| 初级用户 Posts 23 Credits 50 | |
|
The meaning of this sentence is:
/s displays files in the current directory and subdirectories /a-d removes folder information from the results /tc displays by creation time |sort sorts the results of dir /s/a-d/tc, sorting from earliest to latest by creation time |find "-" filters the results of dir /s /a-d /tc|sort to only show lines with "-" |find /v "序列" has the function that since there is a line of result in the result of dir /s /a-d /tc|sort|find "-" that is not wanted, so it removes the line with "序列" from the result of dir /s /a-d /tc|sort|find |
|
| Floor5 不得不爱 | Posted 2006-11-08 00:31 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
In the bat file, use:
FOR /F "tokens=*" %%i IN ('dir/s/b/od') DO @echo %%~ti %%i In the CMD, use: FOR /F "tokens=*" %i IN ('dir/s/b/od') DO @echo %~ti %i |
|
| Floor6 onlykier | Posted 2006-11-08 01:57 |
| 初级用户 Posts 23 Credits 50 | |
|
I need the directory location of the file. Please let the brother upstairs see the original meaning of floor 1.
|
|
| Floor7 namejm | Posted 2006-11-08 02:09 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
The 5F only satisfied one of the requirements of the 3F, and did not handle the other requirement. Based on the 5F, the following code is obtained:
[ Last edited by namejm on 2006-11-7 at 02:15 PM ] |
|
| Floor8 不得不爱 | Posted 2006-11-08 04:40 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
But I tested it, and the output of the code on floor 7 is the same as that on floor 5.
|
|
| Floor9 不得不爱 | Posted 2006-11-08 04:45 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
Could it be that you execute dir/s/b/od and it doesn't display file names with paths?
|
|
| Floor10 namejm | Posted 2006-11-08 07:03 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
Originally posted by Have to Love at 2006-11-7 16:40: Sorry, I didn't compare and test the code of 5F and 7F, which led me to subjectively think that there were differences between the code of 5F and 7F. In fact, the results they display are the same. However, the %%~ti extension in the for statement can only detect the last modification time of the file, but not the creation time. To extract the creation time, you still need to use /tc in dir. Please test the following code by the landlord to see if it is what you need: I found that when using %%~dpnxl to extend the full path of the file, it was simply adding the path where the batch file is located in front of the file name. It seems that this problem is really a bit tricky. Maybe the method of generating a temporary file is needed to fully meet the landlord's requirements. [ Last edited by namejm on 2006-11-7 at 08:26 PM ] |
|
| Floor11 namejm | Posted 2006-11-08 11:23 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
Found a solution, but the drawback is: two temporary files are generated.
|
|
| Floor12 zh159 | Posted 2006-11-08 13:11 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
Low efficiency, but no temporary files will be generated
|
|
| Floor13 不得不爱 | Posted 2006-11-08 23:07 |
| 超级版主 Posts 2,044 Credits 5,310 From 四川南充 | |
|
The one upstairs can't run!
|
|
| Floor14 namejm | Posted 2006-11-09 01:47 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
I mentioned in 10F that the %%~ti in the for statement can only detect the last modification time of the file, and %%~dpnxi simply adds the path where the batch file is located before the file name. Suppose test.bat is located under d:\test, and test.txt is located under d:\test\abc\123, then %%~dpnxi will only expand test.txt to d:\test\test.txt instead of d:\test\abc\123\test.txt. Therefore, using %%~ti and %%~dpnxi (or %%~fi) at the same time is incorrect.
|
|
| Floor15 zh159 | Posted 2006-11-09 04:51 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
I tested it at 12F and it can run. However, for the latter part of the LZ: findstr "-"^|find /v "序列" When testing, I used ^|findstr ".mmf" (mmf is a mobile phone ringtone file)
for /f "delims=" %%a in ('dir/b/s "%%l"') do set Name=%%~fa This line is to search for files of "%%l" again. %%~fa gets the correct path. Because it searches dir/s again, so the efficiency is reduced |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |