Итак, я пытаюсь создать сценарий, который будет делать несколько вещей, но сначала мне нужно что-то скопировать.
Мне нужно скопировать все файлы из каталога A в B, используя пользователя ввод, который будет указывать файлы для копирования на основе серийного номера или его части.
Т.е. После того, как пользователь вводит sn "###" и выбирает папку X или Y, я хочу, чтобы все файлы в папке с Test_1_051724###.txt были скопированы в каталог B.
Вот что у меня есть на данный момент. В конце концов мне нужно получить файлы с компьютера с Linux, подключенного через Ethernet, но я смогу изменить адреса позже, как только выясню, что я делаю не так с битом копирования.
Я мне удалось создать каталог и скопировать файлы, когда я ввожу «тест», но каждый раз, когда я использую номер, я не копирую. Я попробовал несколько вещей, но так и не смог понять, что я делаю неправильно или чего не хватает.
Некоторые рекомендации были бы полезны.
Спасибо ты.
@echo off
:start
setlocal EnableDelayedExpansion
@REM ssh sprocket:[email protected]
@REM set "source_dir=var/TestResults/"
@REM set "dest_dir=C:/ARTE/Test_Reports/"
@REM set "archive_dir=/var/BackupTests/"
@REM ~~~~~~TESTING~~~~~~
set "source_dir=C:\Users\cliljohn\Documents\DCD\EE1\"
set "dest_dir=C:\Users\cliljohn\Documents\DCD\EE1\TestMove"
set "archive_dir=/var/BackupTests/"
rem Prompt the user for SN
set /p partial_filename=Enter the SN to copy:
rem Prompt the user for the directory (EE1 or EE2)
set /p directory=Enter the directory (EE1 or EE2):
@REM rem Prompt the user for the SSH username and password
@REM set /p username=Enter the SSH username:
@REM set /p password=Enter the SSH password:
@REM rem Copy the file from the Test Controller to local machine
@REM if %directory% == EE1 (
@REM scp %username%:%password%@11.200.1.10:/var/TestResults/EE1/%partial_filename%* .
@REM ) else if %directory% == EE2 (
@REM scp %username%:%password%@11.200.1.10:/var/TestResults/EE2/%partial_filename%* .
@REM ) else (
@REM echo Invalid directory. Please enter EE1 or EE2.
@REM goto end
@REM )
rem Copy the file from the Test Controller to local machine
if not exist "C:\Users\cliljohn\Documents\DCD\EE1\TestMove\" mkdir C:\Users\cliljohn\Documents\DCD\EE1\TestMove
for %%I in (%partial_filename%*) do (
if %directory% == EE1 (
scp C:\Users\cliljohn\Documents\DCD\EE1\%%~nI* . "C:\Users\cliljohn\Documents\DCD\EE1\TestMove"
) else if %directory% == EE2 (
scp var/TestResults/EE2/%%~nI* . "C:/ARTE/Test_Reports/EE2"
) else (
echo Invalid directory. Please enter EE1 or EE2.
goto start
)
)
@REM rem Copy the file with the matching partial serial number
@REM for %%f in (%source_dir%*) do (
@REM if "%%~nf" gtr "" if "%%~nf" lss "" if "%%~nf" contains "%partial_filename%" (
@REM copy "%%f" "%dest_dir%"
@REM echo File copied: %%~nxf
@REM )
@REM )
echo.
echo File copy complete...
echo.
goto start
:end
Я попробовал другой подход и получил сообщение об ошибке:
@echo off
:start
rem Prompt the user for the search string
set /p search_string=Enter the search string:
rem Prompt the user to choose the source directory
echo Choose the source directory:
echo 1. EE1
echo 2. EE2
set /p source_dir_choice=Enter 1 or 2:
rem Set the source directory based on the user's choice
if %source_dir_choice% == 1 (
set source_dir="C:\Users\cliljohn\Documents\DCD\EE1\."
set dest_dir="C:\Users\cliljohn\Documents\DCD\EE1\TestMove1"
) else if %source_dir_choice% == 2 (
set source_dir="C:\Users\cliljohn\Documents\DCD\EE1\."
set dest_dir="C:\Users\cliljohn\Documents\DCD\EE1\TestMove2"
) else (
echo Invalid choice. Exiting.
goto end
)
@REM rem destination directory
@REM if %source_dir_choice% == 1 (
@REM set dest_dir=C:\Users\cliljohn\Documents\DCD\EE1\TestMove1
@REM ) else if %source_dir_choice% == 2 (
@REM set dest_dir=C:\Users\cliljohn\Documents\DCD\EE1\TestMove2
@REM ) else (
@REM echo Invalid choice. Exiting...
@REM goto start
@REM )
rem Create the destination directory if it doesn't exist
if not exist "%dest_dir%" mkdir "%dest_dir%"
rem Copy the files that contain the search string
for %%f in ("%source_dir%\*") do (
if "%%~nxf" gtr "" if "%%~nxf" lss "" if "%%~nxf" contains "%search_string%" (
copy "%%f" "%dest_dir%"
echo Copied file: %%~nxf
)
)
echo.
echo File copy complete.
echo.
goto start
:end
Подробнее здесь: https://stackoverflow.com/questions/784 ... ial-number
Попытка скопировать файл из одного каталога в другой, используя часть имени/серийного номера. ⇐ Linux
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение