使用BATCH清理文件名以命名完整路径

时间:2015-04-11 21:43:12

标签: batch-file automation

所有信息都位于文本文件中。我想离开这个:

/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

对此:

/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

说实话,我不知道如何处理这个问题,因为这超出了我的批处理技能。

1 个答案:

答案 0 :(得分:4)

试试这个:

@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
   )
)