dpd3447 2013-09-26 22:32
浏览 152
已采纳

将文件从多个子目录复制到根目录并保留重复项

So I have a list of directories and sub directories with images in them. I need to get then names of all of these files in the same format and I need to edit them for duplicates or images that are from different angles (ie the back). Lets say they are all in

C:\Users\username\Desktop\a........

For example I have an image in:

C:\Users\username\Desktop\a\123\123.jpg
C:\Users\username\Desktop\a\123\back\123.jpg

I want them all to be in C:\Users\username\Desktop\a\ but I want to keep both the back and the front images. I have found dozens of scripts that will move or "flatten" these files into one folder but it always asks to overwrite the image. Is there a way to have it keep the second file and add the 123 (1).jpg like the normal copy function? Or maybe even insert "back" inside of the filename for duplicated? It also doesn't just stop with \back I also have \options folder.

So can I use part of the path name to name the file? So if it has \back in it can I add that to the filename string? Same thing with \options?

So for C:\Users\username\Desktop\a\123\back\123.jpg, I would want:

C:\Users\username\Desktop\a\123.123.jpg
C:\Users\username\Desktop\a\123.back.123.jpg
C:\Users\username\Desktop\a\123.options.image1.jpg
C:\Users\username\Desktop\a\123.options.image2.jpg

I would prefer a batch script to do this, but honestly I will work with PHP, JS, Ruby, anything I don't have to compile. :) Greatly appreciate any help given.

  • 写回答

1条回答 默认 最新

  • duanhe0817825 2013-09-27 08:00
    关注

    Launch this in C:\Users\username\Desktop\a folder and it will write renfile.bat for you to look at before running it, if it does what you need - rename all the files with folder names included.

    @echo off
    echo.@echo off> renfile.bat
    for /f "delims=" %%a in ('dir /b /s /a-d ') do call :next "%%a"
    echo renfile.bat created
    pause
    goto :eof
    :next
    echo "%~1"
    set "var=%~1"
    call set "var=%%var:%cd%=%%"
    set "var=%var:\=.%"
    >>renfile.bat echo ren "%~1" "%var:~1%"
    

    You can follow it up with this to move all the files to the one folder.

    @echo off
    for /r "C:\Users\username\Desktop\a" %%a in (*) do move "%%a" "C:\Users\username\Desktop\a"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64