copying files

good afternoon,

I have this script for copy one file

:local buffer [/file get [/file find name="flash/tmp1/ubuntu_rsa"] contents]
/file print file=("tmp1/ubuntu_rsa"."\00")
/delay 1s
/file set tmp1/ubuntu_rsa contents="$buffer"

and it works great,

how to modify it so that it also copies all files from folder A to folder B?

I asked the chatbot Mikrotik and GPT, they gave something similar, but it still doesn’t work

# Define source and destination directories
:local sourceDir "/source-directory/"
:local destDir "/destination-directory/"

# Get a list of all files in the source directory
:local fileList [/file find where name~"$sourceDir"]

# Loop through each file in the source directory
:foreach file in=$fileList do={
    # Get the file name
    :local fileName [/file get $file name]
    
    # Read the contents of the file
    :local fileContents [/file get $file contents]
    
    # Define the destination file path
    :local destFile ($destDir . [:pick $fileName [:len $sourceDir] [:len $fileName]])
    
    # Write the contents to the destination file
    /file print file=$destFile contents=$fileContents
}

@Liiina Did you try how your current copy script works with large files (eg. 1GB file size)? See here for possible workaround if you gonna go into this endeavour.

thanks for the answers, but i don’t need to copy large files, just three dozen files witch configurations, macros, rsa keys, etc. the largest file does not exceed 1.5 KB. enabling external services is not allowed.

i would be very grateful if someone rewrote my single file script into a proper workflow with
:foreach file in=$fileList do={
..
}

:local sourceDir "source-directory"
:local destDir "destination-directory"

:local fileList [/file find where name~("$sourceDir" . "/")]

:foreach file in=$fileList do={
    :local fileName [/file get $file name]
    :local fileContents [/file get $file contents]
    :local destFile ($destDir . [:pick $fileName [:len $sourceDir] [:len $fileName]])

    /file print file=("$destFile"."\00")
    /delay 3s
    /file set $destFile contents=$fileContents
}

it seems to work, I had to do it myself :frowning:

Is there another way to create a file and write the contents in a way that is not as stupid as “print”, “set” in a file?

I do not know if I should laugh or cry?

Best way to learn new things.

On which ROS version? There is file add command introduced in some 7.x ver., see doc: https://help.mikrotik.com/docs/spaces/ROS/pages/2555971/Files#Files-Createnewfileordirectory where with single command call file with contents can be created.

I’m sad that I had to do everything myself

thanks for the help, changed it to

_/file add name=("$destFile"."\00") type=file contents=$fileContents

/file print file=("$destFile"."\00")

/delay 3s

/file set $destFile contents=$fileContents_

and everything became faster and better!

Are you convinced that a forum is a place where dozens of users just wait on the couch, tapping their feet impatiently, waiting to solve others’ problems?

And then some users who feel like they are the second choice after FakeGPT, they are f–g about.