中国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-08-12 10:05
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Batch processing selective file copying has never been successful, seeking solutions
Printable Version  2,259 / 11
Floor1 evilangell Posted 2010-10-20 10:16
初级用户 Posts 32 Credits 32
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
Floor2 evilangell Posted 2010-10-20 10:19
初级用户 Posts 32 Credits 32
:
: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
Floor3 evilangell Posted 2010-10-20 13:37
初级用户 Posts 32 Credits 32
If you can't drag and drop multiple files, it's okay to drag and drop one file.
Floor4 evilangell Posted 2010-10-20 16:48
初级用户 Posts 32 Credits 32
@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!
Floor5 evilangell Posted 2010-10-20 16:52
初级用户 Posts 32 Credits 32
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. . .
Floor6 qinchun36 Posted 2010-10-21 18:13
高级用户 Posts 400 Credits 609
```
@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 ]
```
Floor7 evilangell Posted 2010-10-21 22:55
初级用户 Posts 32 Credits 32
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.
Floor8 evilangell Posted 2010-10-22 13:58
初级用户 Posts 32 Credits 32
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
Floor9 qinchun36 Posted 2010-10-22 16:13
高级用户 Posts 400 Credits 609
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.
Floor10 yf6122010 Posted 2010-12-09 12:25
新手上路 Posts 18 Credits 18
Learning
Floor11 yf6122010 Posted 2010-12-09 12:25
新手上路 Posts 18 Credits 18
Floor12 acaigg Posted 2010-12-25 12:20
初级用户 Posts 92 Credits 115
Learning
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023