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

本站现有博文333篇,共被浏览918077

本站已经建立2623天!

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