我的文件结构和程序如下:http://i.imgur.com/R7P7HQI.jpg
我有一个名为“Project_ID”的文件夹。
在该文件夹中,我有我的html文件和另一个包含我的设计模板的文件夹,名为01.jpg,02.jpg,03.jpg等等......
在这些html文件中,我会对每张照片进行预览,例如: 01.html,02.html,03.html等......
如果单击并打开01.html,则会看到第一张图像01.jpg。如果您单击该图像,它会将您发送到打开02.jpg的文件“02.html”上的同一文件夹,依此类推,直到您再次访问打开01.html的最后一个html。
... --------------------------------------
我想用批处理文件“自动化”的是:
每次我有一个新项目时,我都必须使用记事本进入每个.html文件,在Profile中更改值“Profile”,并使用我的初始文件夹具有的确切名称(Project_ID)。
然后,我必须用图像文件夹中01.jpg的确切尺寸替换宽度(在我的示例1920中)和高度(在我的示例中为2394)。
当然,我想通过首先查看“初始文件夹的名称(Project_ID)”,“我的.jpg文件在图像中的数量”让我的批处理从头开始用记事本创建所有那些.html文件文件夹“然后创建我在开始时解释的功能所需的确切数量的html文件。我想只用一个批处理文件就有点难了。
任何人都可以提供帮助吗?
答案 0 :(得分:0)
这很痛苦。考虑其他方法:
display.php?project=MyProject&img=1
答案 1 :(得分:0)
如果您要做的是创建照片库,我强烈建议您查看jAlbum。它只需点击几下即可生成您的网络相册,拥有过多的community-developed templates,您甚至可以使用它生成幻灯片。如果阻止右键单击保存图像是您的主要目标,我认为有些模板可以使用Flash Player显示图像。
查看一些sample albums并了解您的想法。
如果您坚持使用自己的模板,请使用GnuWin32 sed查看内联流编辑。您可以使用这样的正则表达式在所有html页面中更改项目:
sed -i -r -e "s/Profile/Project_ID/g" *.html
并对图像宽度执行类似的修改。
然而,当使用sed
开关时,GnuWin32 -i
的内联编辑往往会在其唤醒时留下随机生成的名称的垃圾临时文件。可能最好使用for
循环并重定向sed
的输出,如下所示:
for %%I in (*.html) do (
sed -r -e "s/Profile/Project_ID/g" %%I >%%I.temp
move /y %%I.temp %%I
)
答案 2 :(得分: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