rejetto forum
Software => HFS ~ HTTP File Server => HTML & templates => Topic started by: ScorpAL on July 15, 2009, 04:25:52 PM
-
Hi... All day I try find any example how to check if file exist or not.
Problem description:
We have three files at folder. For example first is test.txt second is test.inf and third is test2.txt
Folder file mask is *.txt. That need for showing only *.txt files in file list (test.txt and test2.txt).
But all files (*.txt and *.inf) loaded to HFS.
At this way we can list test.txt and test2.txt files but have url access to test.inf file ;)
What need:
Trim ".txt" from filename and check has this file pair with extension .inf or not.
If yes - show *.txt file name and text "It has pair" ;)
If no - show *.txt file name and text "It has no pair"
Can you help me?
-
i think you can check that kind of thing with Json :o
yesterday i was looking around for json examples, and i think i saw the file check in json, when you click a btn, it will check if this file exists if not it will result inline on html ??? something like that
sorry i tried to find the link again not there :( i search on google like this json examples ajax
-
Perhaps go read the wiki ^^
http://www.rejetto.com/wiki/index.php/HFS:_Template_macros
-
you can do this only with HFS 2.3
> Trim ".txt" from filename
right click on folder > flags > hide file extension...
> and check has this file pair with extension .inf or not.
> If yes - show *.txt file name and text "It has pair" ;)
> If no - show *.txt file name and text "It has no pair"
{.if|{.filesize|%item-name%.inf.}|it has pair|it has no pair.}
this doesn't actually check file existence, but i hope it will fit your needs (won't work with zero byte files)
> Can you help me?
sure ;)
-
you can do this only with HFS 2.3
Yep. I use HFS 2.3 (242).
> Trim ".txt" from filename
right click on folder > flags > hide file extension...
It's clear. I use it.
> and check has this file pair with extension .inf or not.
> If yes - show *.txt file name and text "It has pair" ;)
> If no - show *.txt file name and text "It has no pair"
{.if|{.filesize|%item-name%.inf.}|it has pair|it has no pair.}
this doesn't actually check file existence, but i hope it will fit your needs (won't work with zero byte files)
Early I try this method. But...
Hm... Strange... Always show It has no pair.
test1.txt
test1.inf
%item-name% show us test1
%item-name%.inf show test1.inf
{.filesize|%item-name%.inf.} show 0
But test1.inf not empty (~50 - 100Kb)
{.filesize|%item-name%.txt.} show 0 but this file not empty.
All my code for example:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>HFS %folder%</title>
<link rel="shortcut icon" href="favicon.ico" />
</head>
<body>
<div id=folder>%folder%</div>
<div id=body>
%up%
<hr />
%files%
</div>
</body>
</html>
[up]
<a class=big href="..">UP</a>
[nofiles]
<div class=big>No file</div>
[files]
%list%
[file]
<a href="%item-url%">%item-name%</a> %item-size%<br />
{.if|{.filesize|%item-name%.inf.}|it has pair|it has no pair.}<br />
{.filesize|%item-name%.inf.}
%item-name%.tbn<br /><br />
[folder]
<a href="%item-url%"><strong>%item-name%</strong></a><br />
[link]
<a href="%item-url%">%item-name%</a><br />
-
Perhaps go read the wiki ^^
http://www.rejetto.com/wiki/index.php/HFS:_Template_macros
Wiki has no document any feature like this.
Wiki has only:
can access but only for current item.
load but... Wiki has no example how it can check exist file or not.
filesize but... result on privious post.
-
Perhaps try to revert the logic, i mean something like :
{.if not|{.filesize|%item-name%.inf.}|it has no pair|it has pair.}
It may appears like a stupid idea, but sometimes it works...
also you can be more specific by using :
{.if|{.>|{.filesize|%item-name%.inf.}|0|.}|it has pair|it has no pair.}
try using differents signs, with appropriate variable to compare.
also, like said at the very end of the template's wiki in "Workaround to the problem", you can try to quote your text answer, but i'm not sure how to do and even if it will do the trick... just try it ;)
should be something like this :
{.if |{.filesize|%item-name%.inf.}|{: it has pair :}|{: it has no pair :} .}
-
Hm...
The problem that {.filesize|%item-name%.inf.} or {.filesize|%item-name%.txt.} (or {.filesize|%item-name%.} with disabled "Hide file extensions in listing" option) always show 0 (ZERO).
May be filesize does not work at that build?
-
Hm...
I try put some file to HFS folder near hfs executable (hfs242.exe) and renam eit to test.inf
Then in template use {.filesize|test.inf.}. It's work! It show me file size.
One problem... I put file at that folder just for experiment.
Realy my HFS executable stored separate from folder archive.
Rejetto, can you add some function (macros) like {.checkFile.} or {.fileexist.} that can work with virtual filesystem?
I try explain my idea.
I have a large collection of movies rhat I wank share for my friend over home network.
Some movies has covers (jpg files).
File system like this one:
Folder "Shared movies" stored separate from HFS executable file at another local disk and contain
movie1.avi <- movie file
movie1.jpg <- movie cover
movie2.avi <- movie file
movie2.jpg <- movie cover
movie3.avi <- movie file (this movie have no cover)
movie4.avi <- movie file (this movie have no cover)
movie5.avi <- movie file
movie5.jpg <- movie cover
Now I try create template where each movie listed as cover image with link to movie file.
If movie has no cover then cover for this movie should be standart predesigned jpg.
Any ideas?
-
Hm...
I try put some file to HFS folder near hfs executable (hfs242.exe) and renam eit to test.inf
Then in template use {.filesize|test.inf.}. It's work! It show me file size.
One problem... I put file at that folder just for experiment.
Realy my HFS executable stored separate from folder archive.
...
here are some variables availables (http://www.rejetto.com/wiki/index.php/HFS:_Template_symbols#Symbols_available_in_section_.5Bfiles.5D)
Using %item-folder% with %item-name%.jpg/.avi may work...
%item-url% should be the video.
...
Now I try create template where each movie listed as cover image with link to movie file.
If movie has no cover then cover for this movie should be standart predesigned jpg.
Any ideas?
I think you could try to use a switch in your template, testing on your videofiles extensions in exemple.
{.switch|%item-ext%|,|avi,mpg,whatever|your if|.}
-
Wow!!!
AvvA, than you very much!
{.if|{.filesize|%item-folder%%item-name%.inf.}|it has pair|it has no pair.}
It's work!
-
the problem was the folder.
good avva ;)