Files: Rename open(still accessed) file on connected filesystem?

Hello everybody, is there a ways to rename a opened file?

Background:
On windows you could do a “rename a.exe b.exe” and after every connection to this files is closed the renaming is done. With files transfer node this is not possible, as this node is only able to delete the sourcefile after successfull copy, i guess.

Howto:
Is is maybe possible to rename a file on a connected filesystem(smb) with java snippet?
BG Karsten

1 Like

You could do it with python

import os

with open("example.txt", "r") as file:
    # Read the contents of the file
    contents = file.read()

# Rename the file
os.rename("example.txt", "new_example.txt")

# Open the renamed file
with open("new_example.txt", "w") as file:
    # Write some text to the file
    file.write("This is the new file.")

# The file is automatically closed when the context manager exits

1 Like

Thank you for the answer. Is the connected filesystem reachable from python?

I would assume yes but I have no way to try for myself currently
br

This seems not to work in Knime 4.52:

[WinError 2] system can not find the file: ‘test.txt’ → ‘new_example.txt’
Traceback (most recent call last):
File “”, line 5, in
FileNotFoundError: [WinError 2] System can not find the file: ‘test.txt’ → ‘new_example.txt’

If i do this with full path (not the connected fily system) it works.
Does thy python node in Knime >= 4.7 have a filesystem port or something similar?

no just table and pickeled object ports
br

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.