Community discussions

MikroTik App
 
luca1234567
newbie
Topic Author
Posts: 31
Joined: Tue May 15, 2018 1:27 am
Contact:

Super-Easy script to create dir

Sun Nov 29, 2020 2:52 am

I found 4 super-easy, it may also customized, scritp to create a full path of a folder.

- NO need of FTP service enable
- NO need of Firewall config
- NO need of User\Password config
- NO need external scritp
- May be easy included in other script

{
:local CreateDirNewPath "NewDir/NewSubDir"
:do {
  /tool fetch address=127.0.0.1 port=443 mode=https src-path="NotExist" dst-path=($CreateDirNewPath."/NotExist")
  /file remove ($CreateDirNewPath."/NotExist")
 } on-error={ }
}

{
:local CreateDirNewPath "NewDir/NewSubDir"
:do {
  /tool fetch https://127.0.0.1/NotExist dst-path=($CreateDirNewPath."/NotExist")
  /file remove ($CreateDirNewPath."/NotExist")
 } on-error={ }
}

This is if you not want "status:failed" in terminal.
{
:execute {
  :local CreateDirNewPath "NewDir/NewSubDir"
  :do {
    /tool fetch address=127.0.0.1 port=21 mode=ftp src-path="NotExist" dst-path=($CreateDirNewPath."/NotExist")
    /file remove ($CreateDirNewPath."/NotExist")
   } on-error={ }
 }
}

This if you can use global variable
{
:global CreateDirNewPath "NewDir/NewSubDir"
:execute {
  :do {
    /tool fetch address=127.0.0.1 port=21 mode=ftp src-path="NotExist" dst-path=($CreateDirNewPath."/NotExist")
    /file remove ($CreateDirNewPath."/NotExist")
   } on-error={ }
 }
}


I suggest to Mikrotik to correct also the scritp to https://wiki.mikrotik.com/wiki/Script_t ... _directory

Best regards
Last edited by luca1234567 on Sat Dec 12, 2020 1:22 am, edited 1 time in total.
 
User avatar
satman1w
Member Candidate
Member Candidate
Posts: 279
Joined: Mon Oct 02, 2006 11:47 am

Re: Super-Easy script to create dir

Mon Nov 30, 2020 1:34 pm

...or you can create folder on your desktop and just drop it in your Winbox / Files wherever you want..
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 872
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 2:01 pm

Following is SUPER easy way of creating a dir using Terminal
/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.
Last edited by mozerd on Mon Nov 30, 2020 3:24 pm, edited 1 time in total.
 
User avatar
bpwl
Forum Guru
Forum Guru
Posts: 2984
Joined: Mon Apr 08, 2019 1:16 am

Re: Super-Easy script to create dir

Mon Nov 30, 2020 2:14 pm

Make and delete a backup, in the wanted directory.?
 
luca1234567
newbie
Topic Author
Posts: 31
Joined: Tue May 15, 2018 1:27 am
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 3:31 pm

@satman1w: This is a method to create it automaticaluy via scritp, or you want that the router call you when it need to create a directory ?

@mozerd: I test the method /ip smb shares on RouterOS v4. and it CANNOT create new sub-folder like NewDir/NewDir2/NewDir3/ in one command. Can you try.

@bpwl: Why write not wanted data, to next delete ?

WHY mikrotik not implement a full set of command to manage file ?
Like copy file, move file, copydirectory, move directory, create directory, etc.

WHY ???
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 872
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 3:52 pm

@mozerd: I test the method /ip smb shares on RouterOS v4. and it CANNOT create new sub-folder like NewDir/NewDir2/NewDir3/ in one command. Can you try.
@luca1234567
You are 100% correct .... I am not able to create new sub-folders like described ..... no problem with root folders.
 
User avatar
CZFan
Forum Guru
Forum Guru
Posts: 2098
Joined: Sun Oct 09, 2016 8:25 pm
Location: South Africa, Krugersdorp (Home town of Brad Binder)
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 11:38 pm

Use winscp to create folder/sub folder?
 
luca1234567
newbie
Topic Author
Posts: 31
Joined: Tue May 15, 2018 1:27 am
Contact:

Re: Super-Easy script to create dir

Mon Nov 30, 2020 11:43 pm

@CZFan
Use winscp to create folder/sub folder?
I repeat:
@satman1w: This is a method to create it automaticaluy via scritp, or you want that the router call you when it need to create a directory ?
Last edited by luca1234567 on Tue Dec 01, 2020 10:16 pm, edited 1 time in total.
 
User avatar
satman1w
Member Candidate
Member Candidate
Posts: 279
Joined: Mon Oct 02, 2006 11:47 am

Re: Super-Easy script to create dir

Tue Dec 01, 2020 2:37 pm

I repeat:
@satman1w: This is a method to create it automaticaluy via scritp, or you want that the router call you when it need to create a directory ?
[/quote]

You're right, but I never had a need to create folders dynamically on Mikrotik router... When that will happen, I will definitely use one of your scripts.
:-)

regards
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Super-Easy script to create dir

Wed Sep 08, 2021 9:26 pm

I made a better script here, instead of using on-error, the tool fetch and the need to leave http(s) service acrive:
viewtopic.php?f=9&t=151644#p878368
 
r00t
Long time Member
Long time Member
Posts: 672
Joined: Tue Nov 28, 2017 2:14 am

Re: Super-Easy script to create dir

Wed Sep 08, 2021 10:36 pm

Seriously, please PLEASE add directory creating function to ROS 7. What's so complicated about this?
Having to use all these workarounds is just DISGUSTING! All these topics should not have even existed to start with...
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Super-Easy script to create dir

Thu Sep 09, 2021 1:12 am

If scripting support is full removed, no one problem coming out using the router as router and the switch as switch...

If is so disgusting, use another vendor with routers and switches full of scripting support.

Who is online

Users browsing this forum: holvoetn and 17 guests