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-30 17:52
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to obtain multiple variables from the outside to support multiple files? Solved View 2,710 Replies 14
Original Poster Posted 2006-12-12 01:42 ·  中国 上海 电信
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
@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 ]
Floor 2 Posted 2006-12-12 05:48 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
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!


@echo off
if not exist "f:\Backup" md "f:\Backup"

:start
if not "%~1"=="" (
move "%~1" f:\Backup\
shift
goto :start)
pause>nul
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
echo +2 2006-12-12 23:42
redtek +5 2006-12-12 23:43
Floor 3 Posted 2006-12-12 06:05 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
When inputting, you add quotes, pass them in and then remove them. If it exceeds 9, you should use shift.
Floor 4 Posted 2006-12-12 06:29 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
TO: upstairs, the main problem the original poster has is not the issue of quotation marks, but the issue of spaces, should!
Floor 5 Posted 2006-12-12 10:29 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
@echo off
call :print %*
exit /b 0

:print
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.
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
youxi01 +4 2006-12-12 10:54
redtek +5 2006-12-12 23:44
echo +2 2006-12-12 23:44
Floor 6 Posted 2006-12-12 10:57 ·  中国 广东 清远 联通
高级用户
★★
Credits 846
Posts 247
Joined 2006-10-27 12:03
19-year member
UID 68504
Gender Male
From 湖南==》广东
Status Offline
The code of the moderator is really extremely concise! Envious!!!
Floor 7 Posted 2006-12-12 11:11 ·  中国 上海 闵行区 电信
初级用户
Credits 47
Posts 23
Joined 2006-09-27 20:54
19-year member
UID 63820
Status Offline
Does %* in the line @echo off
md D:\备份 2>nul
for %%i in (%*) do move …………
equivalent to *.*?
Floor 8 Posted 2006-12-12 11:15 ·  中国 广东 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
%* means all parameters referenced by the call statement, which is completely different from *.*.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
echo +2 2006-12-12 23:53
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 9 Posted 2006-12-12 11:47 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
Originally posted by youxi01 at 2006-12-12 10:57:
The moderator's code is really extremely concise! Envious!!!

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.
Floor 10 Posted 2006-12-12 23:35 ·  中国 上海 电信
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
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 ]
Floor 11 Posted 2006-12-12 23:40 ·  中国 上海 电信
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
Originally posted by youxi01 at 2006-12-11 04:48 PM:
Try the following code, which supports multiple files and drag-and-drop. However, for files with duplicate names, it overwrites them during the move without prompting!!! Improve it yourself if needed!

@ ...

You understand what I mean, hehe. I tested the code.

Supports drag-and-drop operations, supports files with spaces in their names and more than nine files. Great!!!

Thank you, thank you everyone!

[ Last edited by echo on 2006-12-12 at 11:13 AM ]
Floor 12 Posted 2006-12-13 03:23 ·  中国 北京 海淀区 方正集团
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
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!


@echo off

REM Analyze the current date
For /F "tokens=1" %%a in ('date/t') do set Day=F:\print\%%a
REM If %day% does not exist, then create it!
if not exist %day% Md %day%

:o
REM If there are no parameters, open the %day% folder and exit the program (such as double-clicking, used to see what files are inside!)
if == start explorer %DAY% & exit
REM Check whether this path is a file or a folder
dir %1\. >nul 2>nul && goto Folder

REM If it is a file, execute the following command
echo.
echo Moving %~1, please wait!
title Moving "%~nx1", please wait!

move %1 %day%

:shift
REM Check whether the next parameter of the current parameter is empty, if it is, jump out of the program!
If %2#==# exit
Shift
goto o

:Folder
REM If it is a folder, execute the following command
set Folder="%day%\%~nx1"
md %Folder% && xcopy /y /s /i %1 %Folder% && rd /s /q %1
goto shift


[ Last edited by kcdsw on 2006-12-13 at 03:43 AM ]
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
redtek +5 2006-12-13 04:42
echo +2 2006-12-14 01:52
Floor 13 Posted 2006-12-13 04:34 ·  中国 上海 电信
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
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 ]
Floor 14 Posted 2006-12-13 04:42 ·  中国 北京 海淀区 方正集团
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
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 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
echo +2 2006-12-14 01:53
Floor 15 Posted 2006-12-13 04:48 ·  中国 上海 电信
初级用户
★★
Credits 148
Posts 69
Joined 2006-11-23 23:04
19-year member
UID 71504
Gender Male
Status Offline
Originally posted by kcdsw at 2006-12-12 03:42 PM:
Hehe, this program of mine is used every day at 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...



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 ]
Forum Jump: