Nota
¡Ayúdanos a traducir la documentación oficial de Python al Español! Puedes encontrar más información en Como contribuir. Ayuda a acercar Python a más personas de habla hispana.
Acceso a archivos y directorios¶
Los módulos descritos en este capítulo tratan de archivos de disco y directorios. Por ejemplo, hay módulos para leer las propiedades de los archivos, manipular rutas de acceso de forma portátil y crear archivos temporales. La lista completa de módulos en este capítulo es:
pathlib— Rutas de sistemas orientada a objetos- Uso básico
- Rutas puras
PurePathPurePosixPathPureWindowsPath- Propiedades generales
- Operadores
- Acceso a partes individuales
- Métodos y propiedades
PurePath.drivePurePath.rootPurePath.anchorPurePath.parentsPurePath.parentPurePath.namePurePath.suffixPurePath.suffixesPurePath.stemPurePath.as_posix()PurePath.as_uri()PurePath.is_absolute()PurePath.is_relative_to()PurePath.is_reserved()PurePath.joinpath()PurePath.match()PurePath.relative_to()PurePath.with_name()PurePath.with_stem()PurePath.with_suffix()PurePath.with_segments()
- Rutas concretas
PathPosixPathWindowsPath- Métodos
Path.cwd()Path.home()Path.stat()Path.chmod()Path.exists()Path.expanduser()Path.glob()Path.group()Path.is_dir()Path.is_file()Path.is_junction()Path.is_mount()Path.is_symlink()Path.is_socket()Path.is_fifo()Path.is_block_device()Path.is_char_device()Path.iterdir()Path.walk()Path.lchmod()Path.lstat()Path.mkdir()Path.open()Path.owner()Path.read_bytes()Path.read_text()Path.readlink()Path.rename()Path.replace()Path.absolute()Path.resolve()Path.rglob()Path.rmdir()Path.samefile()Path.symlink_to()Path.hardlink_to()Path.touch()Path.unlink()Path.write_bytes()Path.write_text()
- Correspondencia a herramientas en el módulo
os
os.path— Manipulaciones comunes de nombre de rutaabspath()basename()commonpath()commonprefix()dirname()exists()lexists()expanduser()expandvars()getatime()getmtime()getctime()getsize()isabs()isfile()isdir()isjunction()islink()ismount()isdevdrive()join()normcase()normpath()realpath()relpath()samefile()sameopenfile()samestat()split()splitdrive()splitroot()splitext()supports_unicode_filenames
fileinput— Iterar sobre líneas de múltiples flujos de entradastat— Interpretación de los resultados destat()S_ISDIR()S_ISCHR()S_ISBLK()S_ISREG()S_ISFIFO()S_ISLNK()S_ISSOCK()S_ISDOOR()S_ISPORT()S_ISWHT()S_IMODE()S_IFMT()filemode()ST_MODEST_INOST_DEVST_NLINKST_UIDST_GIDST_SIZEST_ATIMEST_MTIMEST_CTIMES_IFSOCKS_IFLNKS_IFREGS_IFBLKS_IFDIRS_IFCHRS_IFIFOS_IFDOORS_IFPORTS_IFWHTS_ISUIDS_ISGIDS_ISVTXS_IRWXUS_IRUSRS_IWUSRS_IXUSRS_IRWXGS_IRGRPS_IWGRPS_IXGRPS_IRWXOS_IROTHS_IWOTHS_IXOTHS_ENFMTS_IREADS_IWRITES_IEXECUF_NODUMPUF_IMMUTABLEUF_APPENDUF_OPAQUEUF_NOUNLINKUF_COMPRESSEDUF_HIDDENSF_ARCHIVEDSF_IMMUTABLESF_APPENDSF_NOUNLINKSF_SNAPSHOTFILE_ATTRIBUTE_ARCHIVEFILE_ATTRIBUTE_COMPRESSEDFILE_ATTRIBUTE_DEVICEFILE_ATTRIBUTE_DIRECTORYFILE_ATTRIBUTE_ENCRYPTEDFILE_ATTRIBUTE_HIDDENFILE_ATTRIBUTE_INTEGRITY_STREAMFILE_ATTRIBUTE_NORMALFILE_ATTRIBUTE_NOT_CONTENT_INDEXEDFILE_ATTRIBUTE_NO_SCRUB_DATAFILE_ATTRIBUTE_OFFLINEFILE_ATTRIBUTE_READONLYFILE_ATTRIBUTE_REPARSE_POINTFILE_ATTRIBUTE_SPARSE_FILEFILE_ATTRIBUTE_SYSTEMFILE_ATTRIBUTE_TEMPORARYFILE_ATTRIBUTE_VIRTUALIO_REPARSE_TAG_SYMLINKIO_REPARSE_TAG_MOUNT_POINTIO_REPARSE_TAG_APPEXECLINK
filecmp— Comparaciones de Archivo y Directoriocmp()cmpfiles()clear_cache()- La clase
dircmpdircmpdircmp.report()dircmp.report_partial_closure()dircmp.report_full_closure()dircmp.leftdircmp.rightdircmp.left_listdircmp.right_listdircmp.commondircmp.left_onlydircmp.right_onlydircmp.common_dirsdircmp.common_filesdircmp.common_funnydircmp.same_filesdircmp.diff_filesdircmp.funny_filesdircmp.subdirs
DEFAULT_IGNORES
tempfile— Generar archivos y directorios temporalesglob— Expansión del patrón de nombres de ruta de estilo Unixfnmatch— Coincidencia de patrones de nombre de archivos Unixlinecache— Acceso aleatorio a líneas de textoshutil— Operaciones de archivos de alto nivel
Ver también
- Módulo
os Interfaces del sistema operativo, incluidas las funciones para trabajar con archivos en un nivel inferior al de Python file objects.
- Módulo
io La biblioteca de I/O integrada de Python, incluidas las clases abstractas y algunas clases concretas, como la I/O de archivos.
- Función incorporada
open() La forma estándar de abrir archivos para leer y escribir con Python.