2014-11-21 107 views
0

我需要编写一个批处理文件,每个文件转换成每个子文件夹。我提出了以下解决方案:的Windows批处理文件:将所有文件中的子文件夹

set INDIR=<some path> 
set OUTDIR=<some path> 

mkdir "%OUTDIR%" 
for /f "tokens=1*delims=." %%f in ('dir %INDIR% /b /a-d') do (
    rem %%f is file name 
    rem %%g is extension 
    call convert_one . %%f %%g 
) 
) 

for /f "delims==" %%d in ('dir %INDIR% /ad /b') do ( 
    rem %%d is relative path 
    mkdir %OUTDIR%\%%d 
    for /f "tokens=1*delims=." %%f in ('dir %INDIR%\%%d /b /a-d') do (
    rem %%f is file name 
    rem %%g is extension 
    call convert_one %%d %%f %%g 
) 
) 

问题是,它只遍历第一级子文件夹。当我添加/秒关键DIR命令返回全pathes,而不是相对的。
我怎样才能提高脚本来处理各级子文件夹?
PS:我需要单独的值为相对路径,文件名扩展名

回答

1
@echo off 
    setlocal enableextensions disabledelayedexpansion 

    set "INDIR=%cd%" 
    set "OUTDIR=..\out" 

    subst :: /d >nul 2>&1 & subst :: "%INDIR%" 
    for /r "::\." %%a in (*) do (
     if not exist "%OUTDIR%%%~pa" md "%OUTDIR%%%~pa" 
     call convert_one ".%%~pa" "%%~na" "%%~xa" 
    ) 
    subst :: /d 

这会创建一个subst驱动器,所以驱动器的根目录指向in文件夹。然后在文件夹结构迭代重建在输出文件夹结构,并要求用指定的参数

1

你不告诉我们convert_one - 但这里有一个一些线索......

for /f "delims=" %%f in ('dir %INDIR% /b /s /a-d') do (
    rem %%~dpnf is file name and path 
    rem %%~dpf is file absolute path 
    rem %%~nf is file name-part 
    rem %%~xf is extension 
    call convert_one "%%~dpf" "%%nf" %%~xf 
) 
) 

for /?|more从提示更多...

(你的子程序中,%〜N代表N =如果需要1..9条报价 - 报价申请意味着"strings containing spaces"被视为一个字符串 - 也许使你的目标目录中有...)

+0

子程序这将是我所需要的,如果我能够从%%%。减去%下载DPF〜。 – deko 2014-11-21 10:21:08

相关问题