1

I have a question about the following batch file: it does it's work perfectly but i'm wondering if the following is possible:

Is there any way for it to let it look in several directories and output the file in that specific directory and then continues to the next until it reached the end of the directory list and then finishes.

So for example:

main dir  -subdir
          -subdir1
          -subdir2
          -ect.

i start the batch in maindir and it will list the files each subdir in an outputfile.rss in that subdir. so it will look like this:

main dir  -subdir - outfile.rss (contains the list of files of this subdir)
          -subdir1- outfile.rss (contains the list of files of this subdir)
          -subdir2- outfile.rss (contains the list of files of this subdir) 
          -ect.

And this is the batch file i would like to "expand". Hopefully someone can help me with this?

@ECHO OFF &SETLOCAL
SET "header1=<rss version="2.0" xmlns:jwplayer="http://rss.jwpcdn.com/">"
SET "header2=    <channel>"
SET "footer1=    </channel>"
SET "footer2=</rss>"

(
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO(!header1!
ECHO(!header2!
ECHO(
ENDLOCAL
FOR %%a IN (*.flv *.mp4) DO (
    ECHO(    ^<item^>
    ECHO(        ^<title^> %%~na ^</title^>
    ECHO(        ^<jwplayer:source file="/temp/records/%%~nxa" /^>
    ECHO(    ^</item^>
)
SETLOCAL ENABLEDELAYEDEXPANSION
ECHO(
ECHO(!footer1!
ECHO(!footer2!
)>outfile.rss  

Thanks in advance.

4

2 に答える 2

0

次のようなことを試すことができます:

@ECHO OFF 
SETLOCAL ENABLEDELAYEDEXPANSION


REM calculate the length of local path 
FOR /L %%n in (1 1 500) do if "!__cd__:~%%n,1!" neq "" set /a "len=%%n+1"

SET "header1=<rss version="2.0" xmlns:jwplayer="http://rss.jwpcdn.com/">"
SET "header2=    <channel>"
SET "footer1=    </channel>"
SET "footer2=</rss>"


(
    ECHO.!header1!
    ECHO.!header2!
    ECHO.

    FOR /R %%a IN (*.flv *.mp4) DO (
        SET "absPath=%%a"
        SET "relPath=!absPath:~%len%!"
        SET "webPath=!relPath:\=/!"
        ECHO.    ^<item^>
        ECHO.        ^<title^> %%~na ^</title^>
        ECHO.        ^<jwplayer:source file="/temp/records/!webPath!" /^>
        ECHO.    ^</item^>
    )
    ECHO. 
    ECHO.!footer1!
    ECHO.!footer2!
) & REM put "> file.rss" here if you want a file 

ENDLOCAL

あなたは、バッチ スクリプトで行うのに役立つことについて少しばかりです。Python、powershell、javascript などの実際のスクリプト言語を使用する方がはるかに良いでしょう。特にこれをさらに拡張する必要がある場合。

于 2013-09-07T20:26:43.507 に答える