Note: This website is archived. For up-to-date information about D projects and development, please visit

Filename Too Long Example

Part of StandardLibraryCategory


This program generates a comma-separated-values (CSV) file with files with filenames that are too long for me to burn them onto a DVD. Apparently, there's some kind of 108-character limit for filenames on a DVD. There's also a limit on CD filenames, but I don't know if it's the same.

When I try to create a DVD on my computer, the DVD-creating software complains if filenames are too long. The program gives me list of the files the offend it, but it's in a little window that I can't resize and it won't let me copy-and-paste the data from it. So now, I can have a friendlier list of files to shorten.


import std.file; /* for listdir */
import std.path; /* for getBaseName */
import std.stdio; /* for writef */
import; /* for File */
import std.string; /* for toString */

const char[] pgmName = "LinesOfCodeExample";
const int max_number_of_characters = 108;

char[] outputData;

int main(char[][] args)
    char[] pathStr;
    char[] outputFileStr;

    if(args.length < 2)
        writefln("Usage: " ~ pgmName ~ " input_path output_file");
        return 0;
        pathStr = args[1];
        outputFileStr = args[2];

    outputData = `"Path","Filename","PathAndFilename",` ~
      `"Length"` ~ \r\n;

    int n = listdirfn(pathStr);

    writef("Number checked: %s\n", n);
    std.file.write(outputFileStr, cast(byte[])outputData);

    return 0;

int listdirfn(char[] pathname)
    int n;
    bool callback(DirEntry* de)
        if (de.isdir)
            writefln("Checking %s",;
            std.file.listdir(, & callback);
            if (getBaseName( > max_number_of_characters)

                outputData ~=  `"` ~ getDirName( ~ `","` ~ 
                  getBaseName( ~ `","` ~ 
         ~ `","` ~ 
                  toString( ~ `"` ~ \r\n;
        return true; // continue

    std.file.listdir(pathname, & callback);
    return n;

Sample batch file

@echo off
dmd FilenameTooLongExample.d
FilenameTooLongExample.exe D:\dwnlds D:\examples\fn_too_long.csv

Tested Version

Tested by compiling with DMD 0.174 and running on Windows 2000.


Partially based on digitalmars.D/33287 (listdir example).