Using BATCH to clean up file names to name full path

狂风中的少年 提交于 2020-01-07 01:22:42

问题


All the information is located in a text file. I would like to go from this:

/var/www/xxx/video_folder_1:
New folder
New folder - Copy
New folder - Copy (10)
New folder - Copy (10) - Copy
New folder - Copy (10) - Copy - Copy
New folder - Copy (11)

/var/www/xxx/video_folder_2:
cideo.mp4
sadasd

To this:

/var/www/xxx/video_folder_1/New folder
/var/www/xxx/video_folder_1/New folder - Copy
/var/www/xxx/video_folder_1/New folder - Copy (10)
/var/www/xxx/video_folder_1/New folder - Copy (10) - Copy
/var/www/xxx/video_folder_1/New folder - Copy (10) - Copy - Copy
/var/www/xxx/video_folder_1/New folder - Copy (11)/
/var/www/xxx/video_folder_2/cideo.mp4
/var/www/xxx/video_folder_2/sadasd

To be honest, I have NOT idea how to approach this as this is way beyond my batch skills.


回答1:


Try this:

@echo off
setlocal EnableDelayedExpansion

for /F "delims=" %%a in (test.txt) do (
   set "line=%%a"
   if "!line:~0,1!" equ "/" (
      set "header=%%a"
   ) else (
      echo !header:~0,-1!/%%a
   )
)


来源:https://stackoverflow.com/questions/29583417/using-batch-to-clean-up-file-names-to-name-full-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!