Return to Snippet

Revision: 47622
at June 11, 2011 13:41 by eliluminado


Initial Code
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# <Application to hide files on Unix systems.>
# Copyright (C) 2011 Alejandro Alvarez <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# http://www.codigopython.com.ar <[email protected]>

import os, sys

def hide(file):
    if not os.path.exists(file):
        return
    archive = os.path.basename(file)
    directorio = os.path.dirname(file)
    if archive[0] == '.':
        return
    else:
        newfile = directorio+'/''.'+archive
        os.rename(file, newfile)

def show(file):
    if not os.path.exists(file):
        return
    archive = os.path.basename(file)
    directorio = os.path.dirname(file)
    if archive[0] != '.':
        return
    else:
        while archive[0] == '.':
            archive = archive[1:]
        newfile = directorio+'/'+archive
        os.rename(file, newfile)

def check(file):
    if not os.path.exists(file):
        return "File does not exist"
    archive = os.path.basename(file)
    if archive[0] == '.':
        return archive + " Is hidden"
    else:
        return archive + " Is not hidden"

if __name__ == '__main__':
    if len(sys.argv) != 3:
        print "The number of arguments entered is not correct"
	file = sys.argv[1]
	action = sys.argv[2]
    if action == '-c':
        print check(file)
    elif action == '-h':
        hide(file)
        print "The file is hidden"
    elif action == '-s':
        show(file)
        print "The file is not hidden"
    else:
        print "The argument entered is incorrect."

Initial URL
http://wiki.codigopython.com.ar/pyhide:aceptando-parametros-desde-la-linea-de-comandos

Initial Description
Accepting parameters from the command line with Python / Aceptando parámetros desde la linea de comandos con Python

Initial Title
Accepting parameters from the command line with Python

Initial Tags

                                

Initial Language
Python