2013-03-21 48 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 
相关问题