So i am trying to create a script that will do several things, but first i need to copy stuff.
I need to copy all files from directory A to B using a user input that will specify the files to be copied based on a serial number or part of one.
I.e. After user types the sn “###” and chooses the folder X or Y, i want the all files in the folder with Test_1_051724###.txt to be copied to directory B.
Here is what i have so far. In the end i need to grab the files out of a linux pc connected via eathernet, but I can change the addresses later once I figure out what im doing wrong with the copy bit.
I have been able to create a dir and copy files when I input “test” but any time i use a number I doe not copy. I tried a few things and haven’t been able to figure out what im doing wrong or missing.
Some guidenc would be great.
Thank you.
@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:UserscliljohnDocumentsDCDEE1"
set "dest_dir=C:UserscliljohnDocumentsDCDEE1TestMove"
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:UserscliljohnDocumentsDCDEE1TestMove" mkdir C:UserscliljohnDocumentsDCDEE1TestMove
for %%f in (%partial_filename%*) do (
if %directory% == EE1 (
if "%%~nf" == "%serial_number%" (
scp C:UserscliljohnDocumentsDCDEE1%%I . C:UserscliljohnDocumentsDCDEE1TestMove
)) 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 File copy complete.
:end