Command to create directory?

I just don’t get it. Isn’t there a straight way to create a directory except “shaman dance” that Google suggests?

RouterOS does not have a proper file manager or directory support.
You can use SMB and then make folders from your Windows Explorer

ftp into the router, then press ? for a list of commands.
mkdir will be most helpful.

Create the folder you want on your desktop and drag it in to ‘Files’ via winbox.

No idea why the script creates user, group and whatever. Given you have http-ssl service enabled this should suffice:

/tool fetch https://127.0.0.1/ dst-path=path/to/create/xxx

Alternatively use whatever webserver. It creates a file as well, just remove that:

/file remove path/to/create/xxx

How about using ‘dot’ in place of ‘xxx’ like below. This way the website won’t be saved as ‘xxx’ file even if is fetched (adding keep-result=no won’t create any directories):

{
# ----- Create directory tree with /fetch -----
# Take note of the 'dot' (or 'space') in place of 'file name',
# this will prevent the fetched website from actually being saved as a file
# even if fetch is successful
:local path "disk1/complex/directory/tree/."
:do { /tool fetch dst-path=($path) url="https://127.0.0.1/"; } on-error={ :put "Script will continue dispite an error"; }
:local otherpath "disk1/some/other/dir/."
/tool fetch dst-path=($otherpath) url="https://www.google.com/"
}

A file name containing just a dot represents the current directory. So you create the directory and try to overwrite it with a file… This results in an error:

  status: failed

failure: cannot open file

With your code you have to catch and ignore the error.
I prefer my clean solution. :winking_face_with_tongue:

In case if anyone is still wondering.
Just create a SMB share and it will create a folder.

Or mount the disk use the ROSE support with NFS, etc too.

But yeah some “/file add” would be much easier on the device. They really are missing the analog of UNIX “touch”. But it doesn’t come up that much since you start running into parsing/editing are also lacking & commands that output files allow a path.

The flowing will do it for you

/ip smb shares add name=sharethis directory=moab
/ip smb shares remove [find name=sharethis]

The 1st directive will create the directory while the 2nd directive will remove the share that is not needed.

Since the ROS Release v7.9 2023.05.02.:

> /file/add name="/MyFolder/MySubFolder/MyFile.txt" contents="Hello MikroTik :)" ;

> /file/print detail where name="MyFolder/MySubFolder/MyFile.txt" ;
  3 name="MyFolder/MySubFolder/MyFile.txt" type=".txt file" size=17 creation-time=may/31/2023 08:45:15 contents=Hello MikroTik :)

> /file/remove numbers="MyFolder/MySubFolder/MyFile.txt" ;

> /file/print detail where name="MyFolder/MySubFolder" ;
  2 name="MyFolder/MySubFolder" type="directory" creation-time=may/31/2023 08:46:05

The first line creates a TXT file, including the folder hierarchy.
The second displays the contents of the File.
The third deletes the File.
The fourth displays the properties of the remaining folder.

Write to existing directory:

> /system/resource/print file="/MyFolder/MySubFolder/ResData.txt" ;       
> /file/print detail where name="MyFolder/MySubFolder/ResData.txt" ;

(!) The symbol for root (“/”) is not consistent.

This is a miracle…
So when RouterOS 7.23.5 (long-term) comes out I will be able to start experimenting on how to use it in production…

1 Like

Hello,

an absolutely genuine, perfect post!
Dis is why it is always worthy coming here.

Thank you, colleague in arms!

1 Like

Thank you very much colleague! :slight_smile: