Script Name: mega_dir_file_exist.sh

Description

Script check to see if a directory or file exist on Mega.nz.


Parameters

-p

Optional: The path to test if it exist
Eg:  -p 'MyPath/myfile'

-i

Optional: The configuration file to use that contain the credentials for the Mega.nz account you want to access.
See Set up .megarc.

-h

Optional: Display Script help

-v

Optional: Display script version

Possible Codes returned from Script

Code

Definition

0

Directory not found

1

Directory is found and is Root

2

Directory found

3

File Found

102

megals not found. Megtools requires installing or properly configure MT_MEGA_LS option of .mega_scriptsrc to point to the megals location

111

Optional argument -i was passed in but the config can not be found or we do not have read permissions


Remarks

Never pass in the directory Root to mega_dir_file_exist.sh as the frist part of the path.

For  -p "/MyPath/myfile" is fine; however, "/Root/MyPath/myfile" will fail.


If -i is omitted then you must have .megarc set in the current users home directory.


The mega_dir_file_exist.sh does not have any logging or output to the terminal. Only the Exit code is set.


If the name of this file "mega_dir_file_exist.sh" is change for any reason then it needs to be reflected in the configuration file. See Configuration File.


Example

Script example to check and see if a file or folder exist on default Mega.nz account on the command line.


# /bin/bash /usr/local/bin/mega_dir_file_exist.sh -p '/MyPath/myfile'; echo $?


If the file exsit above then 3 will echo to the command prompt if file does not exsit then 0 will echo.

Example

Script example to check and see if we have access to Mega.nz


# /bin/bash /usr/local/bin/mega_dir_file_exist.sh; echo $?


or to check a non-default account


# /bin/bash /usr/local/bin/mega_dir_file_exist.sh -i ~/.megarc_other; echo $?


If the file exist above then 1 will echo to the command prompt if file does not exist then 0 will echo.

Related

Set up .megarc

mega_dir_file_exist.sh Latest Source.