2

Having a remote folder, I want to list all files in it using a web browser. Unfortunately, when file names are long, they are truncated. I observe this whichever the browser (Safari, Firefox, Internet Explorer). Is there a simple solution without having to write code?

In Safari, I observed that the browser lists the files in an HTML table. Basically, the structure is:

<table>
<tr><th>...</th><th>...</th><th>...</th></tr>
<tr><td>&nbsp;</td><td><a href="..." >a-very-long-file-name.jpeg</a></td><td>file date and time</td></tr>
<tr><td>&nbsp;</td><td><a href="..." >another-very-long-file-name.jpeg</td><td>file date and time</td></tr>
(...)
</table>

Using the browser developer tool, I tried adding this attribute to both the <td> and <a> elements: style="display:block;width:800px". Without success. Same when trying adding a inline stylesheet in the header.

4
  • 2
    I disagree with several edits done to the original post by user unor, as it changes the nature of the question. The server itself is not truncating file names: using the developer tools, on can see that the file names themselves are not truncated by the server, but only later when displayed by the browser. It is like if the browser is applying some secret stylesheet.
    – OuzoPower
    Commented May 20, 2018 at 9:17
  • 1
    How is the directory listing being generated? Is this the directory index/listing as generated by mod_autoindex on Apache? If so, what Apache version are you on? (Although I'm beginning to doubt this, since you can't simply "add inline stylesheet in the header", yet you mention, "without having to write code"?) Could you include a screenshot of the displayed result in the browser? Are there any external/embedded CSS applied to this document? "Using the browser developer tool..." - what CSS styles do you see being applied to this element?
    – MrWhite
    Commented May 20, 2018 at 10:43
  • FWIW, I don't really see how @unor's edits change the "nature of the question" - the edits seem quite minor?
    – MrWhite
    Commented May 20, 2018 at 11:47
  • @MrWhite I take a different understanding of the new question title than I did the old one. It is a presumptuous edit.
    – Willtech
    Commented May 21, 2018 at 12:49

2 Answers 2

3

I assume you are referring to the auto-generated directory index that Apache (mod_autoindex) generates. In this case, the filename is physically truncated (at 20 bytes by default) in the generated HTML source that comes from the server, so attempting to change the CSS will have no effect (and it will indeed be the same across all browsers).

However, you can change the width that the filename is truncated to with the NameWidth option of the IndexOptions directive in .htaccess. For example:

IndexOptions NameWidth=*

You can specify a fixed width in bytes or * for it to grow to whatever is necessary.

Reference:
https://httpd.apache.org/docs/2.4/mod/mod_autoindex.html#indexoptions

3
  • Thank you, but using the developer tools, I can see that in my case the names are not truncated by the server. They are truncated at the display stage, like if the browser assigned a default width to anchor elements and truncated strings that are longer. I ended up with a very simple PHP script that I posted as a possible solution.
    – OuzoPower
    Commented May 20, 2018 at 9:29
  • How was the directory listing being generated in the first place?
    – MrWhite
    Commented May 21, 2018 at 22:27
  • It worked. Just tried it. Commented Jul 14, 2022 at 20:07
0

I ended up with this very simple PHP script that I put as "index.php" file in the folder from which to list the files. It meets my needs.

<?php
$path = '.';
echo '<pre>';
$files = array_diff(scandir($path),array('.','..'));
print_r($files);
echo '</pre>';
?>

The array_diff() wrapper function is optional; it removes '.' and '..' from the listed files.

The <pre> ...</pre> sandwich allows to display one file per line.

1
  • It seems your browser was using springy tables for some reason in the original case. <pre> ...</pre> gives pre-formatted. Glad that you got it sorted.
    – Willtech
    Commented May 21, 2018 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.