Community discussions

 
upnort
newbie
Topic Author
Posts: 47
Joined: Wed Aug 15, 2018 2:03 am

Actual file names stored in /file

Thu Aug 22, 2019 12:49 am

How are file names handled in scripting? When I run the following snippet, the messages returned are not the human readable file names but some kind of tokenized file name.
# Filename for wildcard filename search.
:local wildcardFilename ($systemIdentity."-".$systemModel."-".$routerOSVersion."-.*backup|rsc")
:set infoMessage "Attempting to delete previous backups."
:put "$infoMessage"
:log info "$infoMessage"
:foreach backupFile in=[/file find name~"$wildcardFilename"] do={
  :do {
    :set infoMessage "Backup Script: Deleting $backupFile"
    :put "$infoMessage"
    :log info "$infoMessage"
    #/file remove $backupFile
    :set infoMessage "Backup Script: Removed $backupFile"
    :put "$infoMessage"
    :log info "$infoMessage"
  } on-error={
    :set errorMessage "Backup Script: Error removing $backupFile"
    :log error "$errorMessage"
    :set scriptError true
  }
}
The output:
Attempting to delete previous backups.
Backup Script: Deleting *FD0200FA
Backup Script: Removed *FD0200FA
Backup Script: Deleting *FD020148
Backup Script: Removed *FD020148
Backup Script: Deleting *FD02014F
Backup Script: Removed *FD02014F
Backup Script: Deleting *FD020151
Backup Script: Removed *FD020151
Backup Script: Deleting *FD020152
Backup Script: Removed *FD020152
Backup Script: Deleting *FD020154
Backup Script: Removed *FD020154
Thanks again. :)
 
User avatar
SiB
Member Candidate
Member Candidate
Posts: 171
Joined: Sun Jan 06, 2013 11:19 pm
Location: Poland

Re: Actual file names stored in /file

Mon Aug 26, 2019 2:33 am

Patch
-:set infoMessage "Backup Script: Deleting $backupFile"
+:set infoMessage ("Backup Script: Deleting ".[/file get $backupFile name])
This "tokenized file name" is UID of element and inside foreach loop you can grab property of every element by using GET function. Sometimes you can discover this property by pressing second time TAB in CLI and sometime just checking if this will give proper syntax.
MTCNA + MTCRE + MTCINE | ~600 users at ~150 RouterBoards in EMEA | Telegram: @SiB_PL | WebChat: Tokonda
WinBox Tip: F6 works as ALT+TAB | Gliffy.com - free network schematic | prnt.sc - free ScreenShot software
 
upnort
newbie
Topic Author
Posts: 47
Joined: Wed Aug 15, 2018 2:03 am

Re: Actual file names stored in /file  [SOLVED]

Tue Aug 27, 2019 3:51 am

Thank you! :)

Who is online

Users browsing this forum: No registered users and 1 guest