Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is difference between root and base directory?

Tags:

python

shutil

I am trying to use shutils.py , make_archive function.
here: https://docs.python.org/2/library/shutil.html#archiving-operations
but I can't understand the difference between root_dir and base_dir.
Here's a simple code using make_archive:

#!user/bin/python
from os import path
from os import curdir
from shutil import make_archive
# Setting current Directory
current = path.realpath(curdir)
# Now Compressing
make_archive("Backup", "gztar", current)

This will create an archive named Backup.tar.gz which contains a . Directory inside it. I don't want the . directory but the whole thing inside in the archive.

like image 744
Heartagramir Avatar asked Oct 25 '15 18:10

Heartagramir


People also ask

What is the difference between root directory and?

Root directory which is referred to as / (a slash) is the topmost level of the system drive while Home directory which is /Users/<short username> (also referred to as ~) comes under the root directory.

What is a base directory?

The base directory is the path on your system that corresponds to the path where your application will be installed. In other words, it's the local representative of %AppDir%.

Is root and home directory the same?

Difference between Root and Home Directory The root directory is the topmost level of the system drive. The home directory is a subdirectory of the root directory. It is denoted by a slash '/'. It is denoted by '~' and has path "/users/username".

What is the root of a folder?

In a folder structure, the root directory is level zero. Data can already be stored in the root directory, and the structure of the system is such that the folders branch out from it, much like a tree. In most representations, the tree is upside down, with the root directory at the top.


2 Answers

Let's consider following dir structure:

/home/apast/git/web/tornado.py
/home/apast/git/web/setup.py

/home/apast/git/core/service.py

/home/apast/git/mobile/gui.py
/home/apast/git/mobile/restfulapi.py

We will try two snippets to clarify examples: 1. Defining base_dir 2. Without defined base_dir

  1. Defining base_dir, we specify which directory we will include on our file:

    from shutil import make_archive
    root_dir = "/home/apast/git/"
    
    make_archive(base_name="/tmp/outputfile",
                 format="gztar",
                 root_dir=root_dir,
                 base_dir="web")
    

    This code will generate a file called /tmp/outputfile.tar.gz with following struct:

    web/tornado.py
    web/setup.py
    
  2. Running without base_dir, like following:

    from shutil import make_archive
    
    root_dir = "/home/apast/git/"
    
    make_archive(base_name="/tmp/outputfile",
                 format="gztar",
                 root_dir=root_dir)
    

    It will product a file containing:

    web/tornado.py
    web/setup.py
    core/service.py
    mobile/gui.py
    mobile/restfulapi.py
    

To define specific folders, maybe it will be necessary use some other technique, like gzip lib directly.

like image 96
Andre Pastore Avatar answered Oct 22 '22 11:10

Andre Pastore


cd in the root_dir... then tar the base_dir... the docs makes me confuse too, read the code, that will make u clear.

like image 2
ouyangbro Avatar answered Oct 22 '22 12:10

ouyangbro