- 1 year ago
Getting full name of file after scp - batch script
To get the full name of a file after using the scp
command in a batch script, you can extract the file name from the source file path. In a batch script, you can use the %~nx1
syntax to extract the file name with extension from the provided file path.
Here's an example batch script that demonstrates how to extract the full file name after using scp
:
batch@echo off
setlocal
REM Run scp command to copy the file
scp user@hostname:/path/to/source/file.txt C:\destination\
REM Extract the file name from the source file path
set "sourceFilePath=user@hostname:/path/to/source/file.txt"
for %%F in ("%sourceFilePath%") do set "fileName=%%~nxF"
echo Full file name: %fileName%
endlocal
In the script above, replace user@hostname:/path/to/source/file.txt
with the actual source file path used in the scp
command. The for
loop with the %~nxF
modifier extracts the file name with extension from the sourceFilePath
variable and stores it in the fileName
variable.
After running the script, the full file name will be displayed using echo %fileName%
.
Make sure to adjust the file paths and incorporate this code snippet into your existing batch script as needed.