This is my batch file:
@echo off
copy /Y "C:\Users\Murray\Desktop\My_File_Name_1.ssl" "C:\Program Files (x86)\Program\config\*.ssl"
There is another file in the destination folder with ssl extension but its name is always different. For that reason, I want to copy my file then overwrite the current file in the destination folder. However, I do not want to specify file name in the destination because it will be always different while having always same extension (ssl as in the sample). This batch file copies the file to the destination folder but keeps other file with ssl extension. What am I missing?
After running this is output:
C:\Users\Murray\Documents>mytest.bat
C:\Users\Murray\Documents>SetLocal EnableExtensions
C:\Users\Murray\Documents>Set "SourceFile=C:\Users\Murray\Desktop\My_Test_File.ssl"
C:\Users\Murray\Documents>Set "Destination=C:\Program Files (x86)\Program\config"
C:\Users\Murray\Documents>For %G In ("C:\Users\Murray\Desktop\My_Test_File.ssl") Do If "%~aG" LSS "-" (GoTo :EOF ) Else If "%~aG" GEQ "d" (GoTo :EOF ) Else Set "TargetFile=" & Set "Mask=*%~xG"
C:\Users\Murray\Documents>If "--a--------" LSS "-" (GoTo :EOF ) Else If "--a--------" GEQ "d" (GoTo :EOF ) Else Set "TargetFile=" & Set "Mask=*.ovpn"
C:\Users\Murray\Documents>For /F "EOL=? Delims=" %G In ('C:\Windows\System32\xcopy.exe "C:\Program Files (x86)\Program\config\*.ssl" ? /HL | C:\Windows\System32\findstr.exe /N .') Do If "%~dG" == "1:" (Set "Target=%~nxG" ) Else If "%~dG" == "3:" Set "Target="
C:\Users\Murray\Documents>If "1:" == "1:" (Set "Target=Test_File.ssl" ) Else If "1:" == "3:" Set "Target="
C:\Users\Murray\Documents>If "2:" == "1:" (Set "Target=1 File(s)" ) Else If "2:" == "3:" Set "Target="
C:\Users\Murray\Documents>If Not Defined Target (GoTo :EOF ) Else If "Ai" == "0 " GoTo :EOF
C:\Users\Murray\Documents>Copy /Y "C:\Users\Murray\Desktop\My_Test_File.ssl" "C:\Program Files (x86)\Program\config\Test_File.ssl"
1 file(s) copied.
Result: Although it says one file copied, in the destination folder I still see Test_File.ssl instead of My_Test_File.ssl which is expected to copy to the destination.