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

本站现有博文342篇,共被浏览1059173次

本站已经建立2731天!

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