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

本站现有博文334篇,共被浏览932224

本站已经建立2641天!

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