![]() |
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-25 23:43 |
47,812 topics / 349,910 posts / today 0 new / 48,264 members |
| DOS批处理 & 脚本技术(批处理室) » How to obtain multiple variables from the outside to support multiple files? Solved |
| Printable Version 2,849 / 14 |
| Floor1 echo | Posted 2006-12-12 01:42 |
| 初级用户 Posts 69 Credits 148 | |
|
@echo off
if not exist "f:\Backup" md "f:\Backup" :start if not "%~1"=="" ( move "%~1" f:\Backup\ shift goto :start) pause>nul Quoting the code from the second-floor brother, I tested it and it supports drag-and-drop operations, which has well solved the problem I mentioned earlier: (Currently it can only support single files, and the file name cannot have spaces. I don't know how to improve it to support multiple files (more than 9) and not be affected by spaces. I changed %1 to "%1" and it prompted that the command syntax is not supported.) However, after testing, it is found that it does not support folders. I don't know how to improve it? Maybe I didn't make it clear earlier, sorry. Actually, I want to put this P into SENDTO to use, or directly drag and drop multiple files onto this P to operate Great gods, please take a look... :lol: [ Last edited by echo on 2006-12-12 at 04:50 PM ] |
|
| Floor2 youxi01 | Posted 2006-12-12 05:48 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
Try the following code, which supports multiple files and drag-and-drop, but for files with duplicate names, it overwrites them during the move without prompting!!! Improve it yourself if needed!
|
|
| Floor3 NaturalJ0 | Posted 2006-12-12 06:05 |
| 银牌会员 Posts 533 Credits 1,181 | |
|
When inputting, you add quotes, pass them in and then remove them. If it exceeds 9, you should use shift.
|
|
| Floor4 youxi01 | Posted 2006-12-12 06:29 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
TO: upstairs, the main problem the original poster has is not the issue of quotation marks, but the issue of spaces, should!
|
|
| Floor5 3742668 | Posted 2006-12-12 10:29 |
| 荣誉版主 Posts 718 Credits 2,013 | |
|
```
@echo off call :print %* exit /b 0 for %%i in (%*) do echo,%%~i goto :eof ``` Don't understand why call must be used for calling? ``` @echo off md D:\Backup 2>nul for %%i in (%*) do move ………… ``` Note that if the parameter contains spaces, quotes should be added. |
|
| Floor6 youxi01 | Posted 2006-12-12 10:57 |
| 高级用户 Posts 247 Credits 846 From 湖南==》广东 | |
|
The code of the moderator is really extremely concise! Envious!!!
|
|
| Floor7 sea2moon | Posted 2006-12-12 11:11 |
| 初级用户 Posts 23 Credits 47 | |
|
Does %* in the line @echo off
md D:\备份 2>nul for %%i in (%*) do move ………… equivalent to *.*? |
|
| Floor8 namejm | Posted 2006-12-12 11:15 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
%* means all parameters referenced by the call statement, which is completely different from *.*.
|
|
| Floor9 3742668 | Posted 2006-12-12 11:47 |
| 荣誉版主 Posts 718 Credits 2,013 | |
Originally posted by youxi01 at 2006-12-12 10:57: To write good code, use as few ifs as possible; to make code robust, put quotes and parentheses around both sides. ![]() You don't need to belittle yourself either, your code is also one of the more creative ones in this forum. |
|
| Floor10 echo | Posted 2006-12-12 23:35 |
| 初级用户 Posts 69 Credits 148 | |
|
Thanks everyone, I've learned. Maybe I didn't make it clear above.
I want it to support drag-and-drop operations, that is, directly drag multiple files to this P for processing, or put this P into SENDTO, which is more worry-free! I didn't make it clear above, sorry, thank you all [ Last edited by echo on 2006-12-12 at 11:13 AM ] |
|
| Floor11 echo | Posted 2006-12-12 23:40 |
| 初级用户 Posts 69 Credits 148 | |
Originally posted by youxi01 at 2006-12-11 04:48 PM: |
|
| Floor12 kcdsw | Posted 2006-12-13 03:23 |
| 中级用户 Posts 179 Credits 404 | |
|
I've been using it for at least half a year, you can modify it yourself.
Haven't seen any un supported files or folders yet Parameters are unlimited! (More than 9 files or folders or files + folders) I made a shortcut for this batch file (can run minimized) One is placed on the desktop and one is placed in sendto Quite time-saving! [ Last edited by kcdsw on 2006-12-13 at 03:43 AM ] |
|
| Floor13 echo | Posted 2006-12-13 04:34 |
| 初级用户 Posts 69 Credits 148 | |
|
First, top it and then read. It seems just what I want, thank you.
I top! It's really good. I can't rate you today, it's restricted. Tomorrow. In the future, if there are good things, bring them out and share more! [ Last edited by echo on 2006-12-12 at 03:38 PM ] |
|
| Floor14 kcdsw | Posted 2006-12-13 04:42 |
| 中级用户 Posts 179 Credits 404 | |
|
Hehe, this program is what I use every day for work.
The purpose is to put the files to be processed into a folder named after the current date, so that the server can get the files from here. (Because if all are placed in one directory, it's easy to have duplicate names or too many files, and the server response is slow.) Then it needs to support all possibilities (except when the file is open) 1. Right-click sendto 2. Drag and drop 3. Easy to view 4. Support folders 5. Remove the original file In addition, for my convenience in operation, I set a shortcut key in its shortcut, and I can open the folder of the current day immediately with one press. I think it's completely using many other functions of the system, which makes this batch processing feel so, so good For example: sendto, shortcut key, running in minimized form, and so on and so forth So I think this thing is actually very suitable for you to take back for backup This folder form named after the date can be retained. Only the target folder needs to be changed. [ Last edited by kcdsw on 2006-12-13 at 04:45 AM ] |
|
| Floor15 echo | Posted 2006-12-13 04:48 |
| 初级用户 Posts 69 Credits 148 | |
Originally posted by kcdsw at 2006-12-12 03:42 PM: Just tested it, it's really great, haha, I won't say more... It seems that everyone has some good treasures hidden! Learned, instructed, and benefited, thank you! :P [ Last edited by echo on 2006-12-12 at 03:53 PM ] |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |