Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.

Log in or register to post/reply in the forum.

Rename file after each write

iperez Sep 13, 2022 05:59 AM

I am trying to create a .txt file to send via ftp.

No problem so far.

But I need the file to change its name to include the last recorded date in the name.

Every five minutes I need:

Name: 202210051025

Name: 202210051030

Name: 202210051035

Thank you very much


nsw Sep 14, 2022 12:34 PM


Do you have the name of the file in a variable already? 

If the only place you can get that date and time is from the file, then use the combination of FileOpen and FileReadLine instructions in a loop to get the last line of the file in to a variable. See CRBaisc Help for FileReadLine which has an Example which shows how to do this. Extract as follows :-

    'FileReadLine example
    FileHandle2=FileOpen ("CPU:read.txt","r",0)
    Loop Until ReadFile2=-1
    FileClose (FileHandle2)

Once you have the last line of the file in a variable, you can then use text manipulation instructions to get just the string you want as the filename in a variable.

When you send the file using FTPClient, send the same name of file everytime, say "DataImportOriginal".

Once the file is sent, then use the FTPClient instruction to rename this default filename on the server to the actual filename you want. Rename option 5 (FTP) or 15 (SFTP) in PutGetOption parameter of FTPClient.

iperez Sep 18, 2022 03:50 PM

Thanks a lot

the option does just what I need

this allows me to greatly simplify the management of files in the datalogger.

Log in or register to post/reply in the forum.