2014-11-21 105 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

相關問題