marchello
Posts: 81
Joined: Fri Oct 11, 2013 8:59 am

check if content of mounted drive is available; then perform

Mon Dec 19, 2016 6:08 pm

Hi all,

My need is to check if content of mounted drive is available at /mnt/folder1/file.txt and then perform [some action] if result is negative.
Please advise how do I achieve it.
Thanks ahead.

User avatar
DougieLawson
Posts: 39626
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: check if content of mounted drive is available; then per

Mon Dec 19, 2016 6:20 pm

What language are you writing your program in? bash? python? c? something else?
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

User avatar
CarlRJ
Posts: 598
Joined: Thu Feb 20, 2014 4:00 am
Location: San Diego, California

Re: check if content of mounted drive is available; then per

Mon Dec 19, 2016 7:18 pm

Haven't actually compiled any of these, and, uh, it's early, so caveat emptor.

Code: Select all

/* C: */
    #include <unistd.h>

    if (access("/mnt/folder1/file.txt", F_OK) != 0) {
        printf("it isn't there\n");
    }

# Perl:
    if (not -e "/mnt/folder1/file.txt") {
        print "it isn't there\n";
    }

# Python:
    import os

    if not os.path.exists("/mnt/folder1/file.txt"):
        print("it isn't there")

# shell script (bash, sh, etc.):
    if [ ! -e "/mnt/folder1/file.txt" ]; then
        echo "it isn't there"
    fi

Return to “General discussion”