Check and create folder in macSolved

Participant
Discussion
3 years ago

Hello folks kinda new here!

Tried the action for executing scripts from hexnode portal to create a folder if it doesn’t already exist on our macs. Ran this command as script I got with some quick google searches.

mkdir -p Data analytics

Here’s the problem though. Its not working as expected and I can’t figure out why since it’s a simple one line command. Any idea what am I getting wrong?

Replies (1)

Marked SolutionPending Review
Hexnode Expert
3 years ago
Marked SolutionPending Review

Hello @zinovia, We’ve got you covered!

You can check if a folder/directory exists and, if absent, create it by providing the complete path to the folder/directory in the script.

For example, mkdir –p /Users/Username/Desktop/Data\ analytics will check if a directory named ‘Data analytics’ exists in the Desktop. If not, it will be created.

Check out more scripts relate to file management from our Sample script repository.

Hope this answer suits your requirements. Should you need any further assistance, please do not hesitate to reach us!

Cheers!
Emma Jones
Hexnode UEM

Save