Recent Ratings for This Post
( 2 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| feiying001 | +1 | 2007-02-21 13:47 |
| huzixuan | +4 | 2007-04-07 23:38 |
Attachments
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!
DigestI
View 34,137 Replies 112
| Rater | Score | Time |
|---|---|---|
| feiying001 | +1 | 2007-02-21 13:47 |
| huzixuan | +4 | 2007-04-07 23:38 |
set /p source= Please enter the path of the file to be backed up:
:: Here, you can prompt to directly drag the backup target into the running window to obtain the source path
for /f "delims=:\" %%i in ("%source%") do set subarea1=%%i
:: It seems to be to obtain the drive letter of the source. Why not use set subarea1=%source:~0,1%
if not "%source%"=="" set source=%source%
:: The meaning of this sentence is unclear, please enlighten me
:: If you want to format the path, you need to use for %%p in ("%source%") do set source=%%~fp
if "%source%"=="" goto input_source
:: It is suggested to assign the selection of directly pressing Enter (that is, %source% is empty) to the operation with high frequency
if "%source%"=="0" exit
if "%source%"=="1" goto backup_task
echo "%source%"|find "%subarea1%:\" > nul
if "%ERRORLEVEL%"=="1" goto input_source
:: Judge whether there is a drive letter in the path? Can it be done with if "%source:~1,2%"==":\"
if "%source%"=="%subarea1%:\" goto forbid
:: Judge whether the path is the root path? When source is C:\\ or C:\., it will not work
if not exist "%source%" goto source_noexist
goto input_object
:: The meaning of object is object, which is ambiguous with the backup target. It is better to change it to target or destination
Originally posted by Climbing at 2006-5-23 13:05:
I respect your patience, but if you're only writing this batch script for file backup, it's actually simpler to use some third-party tools. For example: SecondCopy, or the synchronization software CmdSync, etc. Of course, personal environments are different, so methods vary. Mine is just a suggestion.
set _src=
for %%p in ("%source%") do if exist %%p set _src=%%~fp
if "%_src%"=="" for %%p in (%source%) do if exist %%p set _src=%%~fp
if "%_src:~1,2%"==":\" goto forbid
set source=%_src%
Originally posted by willsort at 2006-5-24 02:47:
Re namejm:
Finally, I don't know what environment you use to write code? But from the fact that the width of the comment reaches 114, it seems that you may be using a wide-screen monitor, so there is no need to worry about the line break browsing problem of the comment. However, according to the code posted in the forum and my system environment (17"+XP+EditPlus2), whether the automatic line break function is enabled or not, the excessive width of the comment affects the readability of the code.
Originally posted by willsort at 2006-5-24 02:47:
Re namejm:
set _src=
for %%p in ("%source%") do if exist %%p set _src=%%~fp
if "%_src%"=="" for %%p in (%source%) do if exist %%p set _src=%%~fp
if "%_src:~1,2%"==":\" goto forbid
set source=%_src%
set source=
set /p source= Please enter the path of the file to be backed up:
for %%p in (%source%) do set source=%%~fp
for /f "delims=:\" %%i in ("%source%") do set subarea1=%%i
title Please enter the source file path
echo ╭────────╮
echo ╭─────────┤Select the file to back up├─────────╮
echo │ ╰────────╯ │
echo │ Operation instructions: │
echo │ │
echo │ This program can back up the specified file within the specified time │
echo │ │
echo │ To the specified location. Please drag the file to be backed up to this window │
echo │ │
echo │ (Recommended practice), or manually enter the full path of the file to be backed up │
echo │ │
echo │ (Paths with spaces need to be enclosed in double quotes with half-width at the beginning and end │
echo │ │
echo │ status; do not enter illegal characters; otherwise │
echo │ │
echo │ Unexpected errors will occur), then press Enter to confirm. │
echo │ │
echo ╰────────────────────────────╯
echo.
echo Press 1 to view the existing backup tasks Press 0 to exit
echo ──────────────────────────────
and cannot apply character color settings again, which is quite a pity.)
[ Last edited by namejm on 2006-5-25 at 13:28 ]
Originally posted by willsort at 2006-5-24 02:47:
Re namejm:
The following statements can remove possible quotation marks in the path, convert the relative path to the absolute path, convert the non-standard path to the standard path (C:\\-->C:\), and judge whether the path effectively exists and whether it is the root path.
set _src=
for %%p in ("%source%") do if exist %%p set _src=%%~fp
if "%_src%"=="" for %%p in (%source%) do if exist %%p set _src=%%~fp
if "%_src:~1,2%"==":\" goto forbid
set source=%_src%
set /p source= Please enter the path of the file to be backed up:
for %%p in (%source%) do set source=%%~fp
for /f "delims=:\" %%i in ("%source%") do set subarea1=%%i
if not "%source%"=="" set source=%source%
if "%source%"=="" goto input_source
if "%source%"=="0" exit
if "%source%"=="1" goto backup_task
echo "%source%"|find "%subarea1%:\" > nul
if "%ERRORLEVEL%"=="1" goto input_source
if "%source%"=="%subarea1%:\" goto forbid
if "%source%"=="%subarea1%:\\" goto forbid
if "%source%"=="%subarea1%:\." goto forbid
if not exist "%source%" goto source_noexist
goto input_destination
set _i=
set source=
set /p source= Please enter the path of the file to be backed up:
for %%s in (%source%) do set /a _i+=1
if "%_i%"=="1" for %%p in (%source%) do set source=%%~p
:: The above two sentences are to judge whether there are quotes in %source%, and if there are, remove them
if "%source%"=="" goto input_source
if "%source%"=="0" goto :eof
if "%source%"=="1" goto backup_task
if not exist "%source%" goto source_noexist
for %%p in ("%source%") do if "%%~fp"=="%%~dp\" goto forbid
goto input_destination