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-25 04:52
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Batch processing selective file copying has never been successful, seeking solutions View 2,093 Replies 11
Original Poster Posted 2010-10-20 10:16 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
Selectively Copy Files.BAT

Function:
1: If this batch processing has not been run yet, I drag and drop a file (or several files) onto this P processing icon, and then I can copy this file (or these several files) to the specified location according to the selection, such as pressing 1 to copy to the root directory of the C drive, pressing 2 to copy to the c:\windows directory, pressing 3 to exit.

2: If I have double-clicked this batch processing, then I drag and drop a file (or several files) onto this P processing window, and then I can copy this file (or these several files) to the specified location according to the selection, such as pressing 1 to copy to the root directory of the C drive, pressing 2 to copy to the c:\windows directory, pressing 3 to exit.

Little brother has tried for a long time and has not succeeded, please big bull help, thank you
Floor 2 Posted 2010-10-20 10:19 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
:
:again
echo.
if "%~f1" neq "" (set FullPathName=%~f1) else (goto ADD)
:ADD
set FullPathName=%~f1
ECHO %FullPathName%
@set choice
@set /p choice= Please select [1→under the windows directory], [2→under the system32 directory], [3→C drive]
echo.
set FullPathName=%~f1
::IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
PAUSE
echo.
if /i "%choice%"=="1" goto windows
if /i "%choice%"=="2" goto system32
if /i "%choice%"=="3" goto CC
echo.
ECHO Incorrect option, press any key to exit
pause
exit
:windows
ECHO "%FullPathName%" will be copied to the windows directory
COPY "%FullPathName%" %SYSTEMROOT%\
pause
goto again

:system32
ECHO "%FullPathName%" will be copied to the system32 directory
COPY "%FullPathName%" %SYSTEMROOT%\system32\
pause
goto again

:CC
ECHO "%FullPathName%" will be copied to the C drive
COPY "%FullPathName%" C:\
pause
goto again

This is a draft, very messy, don't laugh at the big guys
Floor 3 Posted 2010-10-20 13:37 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
If you can't drag and drop multiple files, it's okay to drag and drop one file.
Floor 4 Posted 2010-10-20 16:48 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
@title Copy file to specified path &@color f3&CLS&echo.
:again
@echo.
@if "%~f1" neq "" (set FullPathName="%~f1" &goto Zhijie) else (goto InWindowns)
:InWindowns
@set /p choice=Please drag and drop a file to be copied into this exit (press Enter after dragging in):
@set FullPathName=%choice%
@echo.
:Zhijie
@set /p choice=[1→windows directory], [2→system32 directory], [3→root directory of C drive], [Q→EXIT]
@IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
@echo.
@if /i "%choice%"=="1" goto windows
@if /i "%choice%"=="2" goto system32
@if /i "%choice%"=="3" goto C_Disk
@if /i "%choice%"=="q" EXIT
@if /i "%choice%"=="Q" EXIT
::Filter the situation of mistakenly copying files due to direct pressing Enter
@echo 【!You haven't dragged any file yet!】
@goto again
:windows
@ECHO %FullPathName% has been copied to the windows directory
@COPY %FullPathName% %SYSTEMROOT%\
@pause
@goto again

:system32
@ECHO %FullPathName% has been copied to the system32 directory
@COPY %FullPathName% %SYSTEMROOT%\system32\
@pause
@goto again

:C_Disk
@ECHO %FullPathName% has been copied to the C drive
::if exist %FullPathName% (echo File already exists &goto again) else (@COPY %FullPathName% C:\)
@COPY %FullPathName% C:\
@pause
@goto again


Copying a single file is already okay.
There are a few minor flaws:
1. No judgment on the situation where the file already exists
2. As shown in the picture, after the first time a file is dragged in and successfully copied, if you press Enter blankly, the situation as shown in the picture will occur. It feels that the selected variable is not cleared, but I added @set /p choice=“”, which cannot clear it. But it doesn't affect use. Hope experts can improve it!
Floor 5 Posted 2010-10-20 16:52 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
The picture can't be uploaded, so I'll just copy it over.

The following is copied from cmd.EXE:


Please drag and drop a file that needs to be copied into this exit (press Enter after dragging it in): "C:\Documents and Settin
gs\Administrator\Desktop\OMRON.T"

[1→under the windows directory], [2→under the system32 directory], [3→under the root directory of drive C], [Q→EXIT] 3

"C:\Documents and Settings\Administrator\Desktop\OMRON.T" has been copied to drive C
1 file has been copied.
Press any key to continue. . .

Please drag and drop a file that needs to be copied into this exit (press Enter after dragging it in):

[1→under the windows directory], [2→under the system32 directory], [3→under the root directory of drive C], [Q→EXIT]

3 has been copied to drive C
The system cannot find the specified file.
Press any key to continue. . .

Please drag and drop a file that needs to be copied into this exit (press Enter after dragging it in):

[1→under the windows directory], [2→under the system32 directory], [3→under the root directory of drive C], [Q→EXIT]

3 has been copied to drive C
The system cannot find the specified file.
Press any key to continue. . .
Floor 6 Posted 2010-10-21 18:13 ·  中国 北京 联通
高级用户
★★★
据说是李先生
Credits 609
Posts 400
Joined 2008-04-23 15:55
18-year member
UID 116706
Gender Male
Status Offline
```
@echo off
title Copy files to specified path
color 17&cls&echo.
if == goto DoOneByOne

:DoForEach
if == goto End
echo File %1
call :GetChoice
if /i == goto End
call :CopyOneFile %1
shift /1
goto DoForEach

:DoOneByOne
echo.&echo Please drag and drop a file to be copied into this window (press Enter after dragging it in):
set "fn="
set /p fn=
if == goto DoOneByOne
call :GetChoice
if /i == goto End
call :CopyOneFile %fn%
goto DoOneByOne

:End
echo === Program ended ===
pause>nul
goto EOF

::=========== END ===========

:GetChoice
echo.&echo →WINDOWS directory →SYSTEM32 directory →Root directory of drive C →Exit
set "choice="
set /p choice=
if /i == goto GetChoice
set "loc="
if /i == set "loc=%SYSTEMROOT%\"
if /i == set "loc=%SYSTEMROOT%\system32\"
if /i == set "loc=C:\"
if == set "choice=Q"
goto EOF 2>nul

:CopyOneFile
cls&echo.
if exist "%loc%\%~nx1" (
echo *** "%loc%%~nx1" already exists ***
) else (
copy %1 "%loc%" 1>nul&&echo Successfully copied "%~nx1" to "%loc%"
)
echo.
goto EOF 2>nul



[ Last edited by qinchun36 on 2010-10-22 at 16:09 ]
```
Floor 7 Posted 2010-10-21 22:55 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
If you drag a bunch of things onto the batch file icon, it will only ask once where to copy them.

Answer: According to 1, 2, 3, select the corresponding directory.
Floor 8 Posted 2010-10-22 13:58 ·  中国 浙江 宁波 电信
初级用户
Credits 32
Posts 32
Joined 2008-04-18 17:22
18-year member
UID 116262
Gender Male
Status Offline
There is a question:
What is the function of shift /1?

It is best that after dragging a file to this batch processing icon, the file name of the dragged - in file can be displayed
Floor 9 Posted 2010-10-22 16:13 ·  中国 北京 联通
高级用户
★★★
据说是李先生
Credits 609
Posts 400
Joined 2008-04-23 15:55
18-year member
UID 116706
Gender Male
Status Offline
You don't know how many times you dragged them onto the batch file icon, and then had to copy each one, so you had to use shift to get each parameter.

For the function of shift, you can go to see the instructions or check related posts. It's probably the meaning of shifting the following parameters. A few words can't explain it clearly.
Floor 10 Posted 2010-12-09 12:25 ·  中国 广东 深圳 诺瓦科技发展有限公司
新手上路
Credits 18
Posts 18
Joined 2010-12-06 16:28
15-year member
UID 178780
Gender Male
Status Offline
Learning
Floor 11 Posted 2010-12-09 12:25 ·  中国 广东 深圳 诺瓦科技发展有限公司
新手上路
Credits 18
Posts 18
Joined 2010-12-06 16:28
15-year member
UID 178780
Gender Male
Status Offline
Floor 12 Posted 2010-12-25 12:20 ·  中国 广东 东莞 中移铁通
初级用户
★★
Credits 115
Posts 92
Joined 2010-12-24 16:57
15-year member
UID 179794
Gender Male
Status Offline
Learning
Forum Jump: