python from pathlib import Path path = Path("path/to/file.txt") python filename = path.name parent_dir = path.parent absolute_path = path.absolute() is_directory = path.is_dir() is_file = path.is_file() python new_path = path / "subdir" / "file.txt" python for file in path.glob("*.txt"): print(file) python content = path.read_text() path.write_text("Hello, World!") path.write_text("Hello, World!", append=True) python from pathlib import Path path = Path("path/to/file.txt") filename = path.name parent_dir = path.parent absolute_path = path.absolute() is_directory = path.is_dir() is_file = path.is_file() new_path = path / "subdir" / "file.txt" for file in path.glob("*.txt"): print(file) content = path.read_text() path.write_text("Hello, World!") path.write_text("Hello, World!", append=True)


上一篇:
下一篇:
切换中文