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

本站现有博文340篇,共被浏览1018364次

本站已经建立2718天!

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