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

本站现有博文339篇,共被浏览996018次

本站已经建立2706天!

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