2013-03-21 30 views
0

我的文件結構和過程是這樣的:http://i.imgur.com/R7P7HQI.jpg需要有關如何創建一個批處理文件信息編輯多個HTML文件

  • 我有一個名爲「PROJECT_ID」文件夾中。

  • 這個文件夾裏,我有我的HTML文件,包含我的設計模板命名01.JPG,02.JPG,03.jpg和其他文件夾等等...

  • 在這些HTML文件,我做每張照片的預覽,例如01.html,02.html,03.html等等...

  • 如果您點擊並打開01.html,您會看到第一張圖片01.jpg。如果您點擊該圖片,它會將您發送到文件「02.html」中打開02.jpg等的文件夾,直到您到達最後一次打開01.html的html。

-------------------------------------- ...

我想用批處理文件「自動化」的東西是:

每次我有一個新的項目,我必須用記事本進入每個.html文件,在Profile中更改值「Profile」確切的名稱我的初始文件夾有(Project_ID)。

然後,我必須用圖像文件夾中我的01.jpg的確切尺寸替換寬度(在我的示例中爲1920)和高度(在我的示例中爲2394)。

當然,我想讓我的批量從頭開始用記事本創建所有這些.html文件,首先查看「初始文件夾的名稱(Project_ID)」,「我的.jpg文件的數量圖像文件夾「,然後創建我在開始時解釋的功能所需的html文件的確切數量。我想這只是一個批處理文件有點難。

任何人都可以幫忙嗎?

+0

有沒有你不使用服務器端,甚至客戶端編程解決方案,自動執行所有這些理由嗎?它是針對dekstop還是針對internet/intranet? – hexblot 2013-03-21 13:16:12

+1

@hexblot:從他的可愛嘗試來看,不是爲了保存圖像,而是後者。 – himself 2013-03-21 13:21:30

+0

@himself:它甚至沒有認識到這是爲了防止圖像保存:P – hexblot 2013-03-21 13:59:49

回答

0

這是一個很痛苦的事情。考慮其他方法:

  • 寫一個HTML頁面加載和顯示不同的圖像與JavaScript。然後,除了項目名稱外,您不必更改任何內容。
  • 寫一個PHP腳本返回不同的圖像,然後像這樣調用它:display.php?project=MyProject&img=1
  • 至少,使用合理的東西,如python。
0

如果你想要做的是創建一個照片庫,我強烈建議你看看jAlbum。它只需點擊幾下鼠標即可生成您的網絡相冊,並有大量的community-developed templates,您甚至可以用它生成幻燈片。如果阻止右鍵單擊保存圖像是您的主要目標,我認爲有一些模板可以使用Flash Player顯示圖像。

查看幾個sample albums,看看您的想法。


如果你堅持要用自己的模板,看看在線流編輯與GnuWin32 sed。您可以使用這樣的正則表達式在所有html頁面中更改您的項目:

sed -i -r -e "s/Profile/Project_ID/g" *.html 

並對您的圖像寬度執行類似的修改。

但是,當使用-i開關時,GnuWin32 sed的內聯編輯往往會在其尾部留下隨機生成的垃圾臨時文件。也許是更好地使用for環路和重定向的sed像這樣的輸出:

for %%I in (*.html) do (
    sed -r -e "s/Profile/Project_ID/g" %%I >%%I.temp 
    move /y %%I.temp %%I 
) 
0
@ECHO OFF 
SETLOCAL 
:: Get directory from cmdline 
SET sourcedir=%~1 
IF NOT DEFINED sourcedir ECHO Require source directory&GOTO :EOF 
IF NOT exist "%sourcedir%\*.jpg" ECHO No JPGs found IN %sourcedir%&GOTO :EOF 
:: 
:: get name of project (last element in path) 
:: 
FOR %%i IN ("%~1") DO SET project=%%~ni 
ECHO project is %project% 
:: Create subdir for HTMLs 
SET "newhtmls=%sourcedir%\newhtmls" 
MD "%newhtmls%" 2>NUL 
:: 
:: %2 is the name of a file containing .jpg names in the order 
:: in which they are to appear. 
:: 
:: If %2 is missing, create a list file 
SET imgseqlist=%2 
IF DEFINED imgseqlist GOTO haveseq 
SET imgseqlist=%temp%\htmlfilelist.txt 
SET dellist="%imgseqlist%" 
DIR /b /a-d /ON "%sourcedir%\*.jpg" >"%imgseqlist%" 
:haveseq 
:: 
:: Build file of image details 
:: I use IRFANVIEW 
:: 
SET imgdetails=%temp%\imagedetails.txt 
SET dellist=%dellist% "%imgdetails%" 
"C:\Program Files (x86)\irfanview\i_view32.exe" "%sourcedir%\*.jpg" /info="%imgdetails%" 
:: 
:: Now let's process 
:: 
(SET firstimg=) 
FOR /f "usebackqdelims=" %%i IN ("%imgseqlist%") DO (
IF DEFINED firstimg (SET nextimg=%%i&CALL :generate) ELSE (SET firstimg=%%i) 
(SET currimg=%%i) 
) 
:: Do the last one... 
SET nextimg=%firstimg% 
CALL :generate 

:: And finally delete the tempfile 
DEL %dellist% 

GOTO :EOF 

:generate 
:: output filename=current imagename -last 4 chars (.jpg) 
SET outfile=%currimg:~0,-4%.html 
SET nexthtml=%nextimg:~0,-4%.html 
:: 
:: Look up the details of your image. 
:: using IRFANVIEW format 
:: 
(SET setdetails=) 
FOR /f "usebackq tokens=1,2,4,6" %%d IN ("%imgdetails%") DO (
IF DEFINED setdetails IF "%%e"=="dimensions" (SET width=%%f&SET height=%%g&SET setdetails=) 
IF /i %%d==[%nextimg%] SET setdetails=Y 
) 
:: I'd have filled out these details if you'd posted them 
:: rather than just a picture :(
>%newhtmls%\%outfile% (
ECHO ^<!DOCTYPE...transitional.dtd"^> 
ECHO ^<html...xthml"^> 
ECHO ^<head^> 
ECHO ^<meta...-8" /^> 
ECHO ^<title^>%project^</title^> 
ECHO ^<...and so ON...^> 
ECHO   background-image:url(images/%currimg%^); 
ECHO ^<...and so ON...^> 
ECHO ^</head^> 
ECHO. 
ECHO ^<body^> 
ECHO ^<a href="%nexthtml%"^>^<img src="images/blank.gif" width="%width%" height="%height%" /^>^</a^> 
ECHO ^</body^> 
ECHO ^</html^> 
) 
GOTO :eof 
相關問題