Page 1 of 1

Renaming files on remote server

Posted: Wed Sep 19, 2018 10:38 am
by hatchet
Hi,

I wonder if someone could help me with this, I've been trying various options to get this to work and I either get a syntax error or the job executes but nothing is renamed.

I have a remote FTP server with files in "\myfolder" matching "M*.TXT".
There may be 1 file there at a given time, or multiple files.
I want to rename them all when the job executes to "R3*.TXT".
I don't care what the rest of the filename is, so the 'M' can be preserved or overwritten as long as the filename begins "R3"

This is what I currently have and executes without errors but nothing is renamed - I have test files in the correct location.
I have test files in place but I don't know if it's failing due to the naming syntax, the folder syntax or what.
Code: Select all
<ftp resourceId="Server" version="1.0">
			<rename searchPattern="M*.TXT" patternType="wildcard" replaceWith="R3*.TXT">
				<fileset dir="\myfolder">
					<wildcardFilter>
						<include pattern="M*.TXT" />
	                        </fileset>
			</rename>
		</ftp>

Re: Renaming files on remote server

Posted: Fri Sep 21, 2018 9:07 am
by Support_Andy
How to use the rename command on a FTP server
See attachment for associated images to steps below
rename_FTP_forum.docx
Step by Step FTP instructions
(158.54 KiB) Downloaded 938 times
1. Start with a timestamp task

2. List the files on the FTP server that match the format to rename

3. Use a For Each Loop to Iterate over the new ${fileList} variable created from step 2

4. Rename using the Input Files Variable ${cur} and use Search Pattern of M*.txt and replace with R3*_${CurrentTimeMillis()}.txt

NOTE: The replace action will fail if a file with that name exists on the remote server. For this reason, the addition of the millisecond timestamp can overcome that limitation.

5. Folder contents before rename
"M9901.txt ","Mandy 9.txt", "M123.txt"
6. Folder contents after rename
"R399101_1537535252915.txt", "R3andy 9_1537535252949.txt", "R3123_1537535252888.txt"