Skip to main content

Python内置文件和路径处理函数的集合和扩展。

Project description

fs-map

项目简介

Python内置文件和路径处理函数的集合和扩展。

安装教程

pip install fs-map

功能说明

  • 集成函数
  1. os 模块
# 函数列表
'''
listdir, 
mkdir, 
rename, 
replace, 
rmdir,
remove,
makedirs,
removedirs,
renames
'''

# 参考文档 
# https://docs.python.org/zh-cn/3/library/os.html#module-os
  1. os.path 模块
# 函数列表
'''
exists, 
getsize, 
isdir, 
isfile, 
normcase, 
isabs, 
join, 
splitdrive, 
split, 
splitext, 
basename, 
dirname, 
normpath, 
abspath, 
realpath, 
relpath
'''

# 参考文档 
# https://docs.python.org/zh-cn/3/library/os.path.html#module-os.path
  1. shutil 模块
# 函数列表
'''
copyfileobj, 
copyfile, 
copymode, 
copy, 
copy2, 
ignore_patterns, 
copytree, 
rmtree, 
move
'''

# 参考文档 
# https://docs.python.org/zh-cn/3/library/shutil.html#module-shutil
  1. glob 模块
# 函数列表
'''
glob, 
glob0, 
glob1, 
iglob,
escape
'''

# 参考文档 
# https://docs.python.org/zh-cn/3/library/glob.html#module-glob
  • 扩展函数
def get_filename(path):
    '''
    Returns a file name with a suffix
    '''

    _, filename = split(path)
    return filename


def get_filename1(path):
    '''
    Returns a file name that does not contain a suffix
    '''

    filename = get_filename(path)
    filename, _ = splitext(filename)
    return filename


def get_ext(path):
    '''
    Returns the file suffix
    '''

    _, ext = splitext(get_filename(path))
    return ext


def normcase1(path):
    '''
    Converts all characters in the path to lowercase and forward slashes to backslashes
    '''

    return normcase(path).replace('\\', '/')


def normpath1(path):
    '''
    Converts forward slashes in a path to backslashes
    '''

    return normpath(path).replace('\\', '/')

实例

import fs


'''
集成函数实例
'''
# 判断文件是否存在
print(fs.exists('file.txt'))


'''
扩展函数实例
'''
# 获取文件后缀
print(fs.get_ext('c:/a/b/c.txt'))
# 输出结果:.txt

# 获取带后缀的文件名
print(fs.get_filename('c:/a/b/c.txt'))
# 输出结果:'c.txt'

# 获取不带后缀的文件名
print(fs.get_filename1('a.c.txt'))
# 输出结果:'a.c'

# 路径标准化的
print(fs.normcase1('c:\\A/b/c.txt'))
# 输出结果:c:/a/b/c.txt
print(fs.normpath1('c:\\A/b/c.txt'))
# 输出结果:c:/A/b/c.txt

参考文献

https://docs.python.org/zh-cn/3/py-modindex.html

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fs-map-0.0.3.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fs_map-0.0.3-py3.8.egg (4.4 kB view details)

Uploaded Egg

File details

Details for the file fs-map-0.0.3.tar.gz.

File metadata

  • Download URL: fs-map-0.0.3.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for fs-map-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7060c737e04b74d1baa1145650083c8805dce931ca8c768fa7a8c37331f42324
MD5 b133b0ccecbfea5ca56a015f5abca139
BLAKE2b-256 ac52d9e649130feb48c30040ec9cb7046a37bdf64f18b8ec5f00106f3575f34e

See more details on using hashes here.

File details

Details for the file fs_map-0.0.3-py3.8.egg.

File metadata

  • Download URL: fs_map-0.0.3-py3.8.egg
  • Upload date:
  • Size: 4.4 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for fs_map-0.0.3-py3.8.egg
Algorithm Hash digest
SHA256 5e3906707387eafcd4e8a2afbe33c6e5555ccaaa4ad3d7de58852c405e907a64
MD5 5ad43ccc477297ac5773f6e76c884370
BLAKE2b-256 d9f88f0a7d4a980d9e0a890b613d0fa4e267ff40f977428f24cd5d7dd5c43c4e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page