I am using dirEntries to iterate over files to rename them.

I am renaming them in a loop(will change but added code for testing).


In DMD the renaming works but in LDC the renaming fails. It fails in a way that I can't quite tell and I cannot debug because visual D is not working properly for LDC.

The code essentially look like the following:


        auto dFiles = dirEntries(loc, mask, _mode);
        
        foreach (d; dFiles)
        {               

           auto newName = Recompute(d.name)
           writeln(newName);
           rename(d.name, newName);
        }

but when I comment out rename, it works under LDC.

The funny thing is, newName is printed wrong so Recompute is effected by the rename.

This shouldn't occur.

Now, dirEntries is a range, so I'm curious if the recomputation is occurring after the rename(if it did then the recomputation would be invalid and produce the results it is producing)?

When I forcably convert dirEntries in to an array(manually, unfortunately, as I can't seem to use array() on dirEntries), everything works).


        struct file { public string name; }
        
        auto dFiles = dirEntries(loc, mask, _mode);

        file[] files;

        foreach (d; dFiles)
        {
                file f;
                f.name = d.name;
                files ~= f;
        }

        foreach (d; files)
        {               

           auto newName = Recompute(d.name)
           writeln(newName);
           rename(d.name, newName);
        }

While it works, the main issue is that a different behavior is observed between DMD and LDC in the first case.

It would be nice to know how to simplify the code though so "lazy" evaluation of dirEntries did not occur.

Reply via email to