EADST

Copy and Rename File When Existing Same Name

Python: Copy and Rename File When Existing Same Name

import os
import shutil

def rename_copy(file_path, out_dir):
    name = os.path.basename(file_path)
    if not os.path.exists(os.path.join(out_dir, name)):
        save_path = os.path.join(out_dir, name)
        shutil.copy(file_path, save_path)
    else:
        base, extension = os.path.splitext(name)
        print(base, extension)
        i = 1
        while os.path.exists(os.path.join(out_dir, '{}_{}{}'.format(base, i, extension))):
            i += 1
        save_path = os.path.join(out_dir, '{}_{}{}'.format(base, i, extension))
        shutil.copy(file_path, save_path)
    return save_path

path = "./copy/"
input_path = "test.jpg"
print(path, safe_copy(input_path, path))
相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
hf NLTK Agent 递归学习法 Translation Quantize 飞书 多线程 Pandas Permission Pickle Input LeetCode SPIE Random 云服务器 LoRA Vim mmap Markdown XML CTC VSCode CV Search Pytorch ONNX Bipartite Food Base64 FP64 签证 腾讯云 Miniforge DeepStream 音频 Paper v0.dev Quantization RGB 图标 Anaconda PDB BTC 阿里云 IndexTTS2 FastAPI Paddle CSV 论文 搞笑 顶会 EXCEL GIT Color 报税 SQLite TensorRT Nginx git 净利润 CLAP Hotel Logo TensorFlow Hungarian Firewall Clash 域名 Card NLP Crawler Numpy printf InvalidArgumentError LLM Jetson Shortcut 强化学习 scipy uWSGI Bert Knowledge 继承 uwsgi Tracking Mixtral GPT4 Password Ptyhon Claude HuggingFace Rebuttal OpenCV Django TTS Dataset SAM CAM PyTorch Github Git Bin SQL 第一性原理 Streamlit FP8 Qwen2.5 Jupyter diffusers CC Baidu 财报 FP16 Data Pillow GPTQ Image2Text Plate Qwen2 OCR XGBoost Windows Freesound ModelScope VPN TSV PyCharm FlashAttention Gemma VGG-16 Distillation Conda Vmess ChatGPT GoogLeNet Statistics Disk CUDA 多进程 Animate DeepSeek OpenAI llama.cpp Proxy NameSilo Plotly Template MD5 BeautifulSoup QWEN Website Domain Land Python C++ Hilton Ubuntu Review Bitcoin WAN Video Magnet v2ray CEIR News COCO 版权 icon ResNet-50 Transformers Heatmap Interview BF16 Sklearn 证件照 Zip RAR LaTeX 关于博主 PIP logger Linux AI YOLO 图形思考法 Algorithm JSON PDF LLAMA Michelin 算法题 UI Cloudreve tar tqdm SVR HaggingFace transformers GGML Qwen Use Datetime git-lfs Web Tensor Docker Math Google Safetensors Augmentation 论文速读 UNIX Breakpoint WebCrawler Llama Excel FP32 Diagram Attention torchinfo API Tiktoken 公式
站点统计

本站现有博文327篇,共被浏览826474

本站已经建立2533天!

热门文章
文章归档
回到顶部