Renaming file extension after uploading to a remote server in WinSCP in batch file

70 views Asked by At

I have a script that uploads files to a remote server using WinSCP. The files are processed and deleted by the receiver on the remote server. I would like to upload only new files being written to the local server, and once uploaded, change the file extension from .txt to .csv. This way, when the script runs again, it will only upload new files with the .txt extension, ignoring those that have already been uploaded with the .csv extension.

This what I have currently but it won't rename the files on the local server. If I use ren *.txt *.csv it will rename them on the remote server.

lcd C:\Files
cd /directory

put -filemask="*.txt" -latest -nopreservetime *

lcd C:\Files
!ren *.txt *.csv

exit
1

There are 1 answers

0
Martin Prikryl On

WinSCP does not allow you to rename local files.

But you can rename them from your batch file, after WinSCP finishes.

cd /D C:\Files

winscp.com /script=upload.txt ...

if errorlevel 0 ren *.txt *.csv