Path.rename

Path.rename(...)

Description

Documentation for Path.rename.

Python Python Pathlib Official Docs

Real-World Examples

Practical code examples showing how Path.rename is used in real projects.

except Exception as e:
        print(f"Error in read_text: {str(e)}")
        return f"[Error: {str(e)}]"

@app.post("/rename")
async def rename_item(request: RenameRequest):
    try:
        # Get the absolute path
        abs_path = os.path.join(base_directory, request.path)
        if not os.path.exists(abs_path):
            return JSONResponse(
                status_code=404,
                content={"success": False, "error": f"Path not found: {request.path}"}
            )

        # Get directory and new path
        dir_path = os.path.dirname(abs_path)
        new_abs_path = os.path.join(dir_path, request.new_name)

        # Check if target already exists
        if os.path.exists(new_abs_path):
            return JSONResponse(
                status_code=400,
                content={"success": False, "error": f"A file or directory with name '{request.new_name}' already exis...
gh_pkgs[name].add(normalize_url(k))
    gh_pkgs = {k: list(v)[0] for k, v in gh_pkgs.items()}
    gh_pkgs = pd.DataFrame(gh_pkgs.items(), columns=["name", "url"])
    # only consider github packages that also exist in pypi and have the same url found by metadata retriever
    gh_pkgs = gh_pkgs.merge(
        df[["name", "version", "redirected"]].rename(columns={"redirected": "url"}),
        on=["name", "url"],
    )
    print(
        f"GitHub source: {len(gh_pkgs['name'].unique())} packages, {len(gh_pkgs)} releases"
    )

    top4000_pkgs = df[
        df["name"].isin(downloads.head(4000)["name"]) & (df["redirected"] != "")
    ][["name", "version", "redirected"]]
    top4000_pkgs.rename(columns={"redirected": "url"}, inplace=True)
    print(
        f"Top 4000 PyPI packages: {len(top4000_pkgs['name'].unique())} packages, {len(top4000_pkgs)} releases"
    )

    res = gh_pkgs.merge(top4000_pkgs, how="outer", indicator=True)
    res["github"] = res["_merge"].apply(
        lambda x: True if x in ["left_only", "both"] else False
    )
    res["top4000"] = res["_merge"].apply(