in reply to Renaming a group of files occassionally deletes some

Could it essentially be going too fast and renaming some to "" which causes Windows to delete them? I figured an error would appear somewhere if it failed to rename something.

from perldoc -f rename:

rename OLDNAME,NEWNAME Changes the name of a file; an existing file NEWNAME will be clobbered. Returns true for success, false otherwise.
C:\temp>touch foo1.txt C:\temp>touch foo2.txt C:\temp>dir foo?.txt Il volume nell'unità C non ha etichetta. Numero di serie del volume: 0464-729A Directory di C:\temp 01/06/2007 19.36 0 foo1.txt 01/06/2007 19.37 0 foo2.txt 2 File 0 byte 0 Directory 4.888.121.344 byte disponibili C:\temp>perl -e "rename 'foo1.txt', 'foo2.txt'" C:\temp>dir foo?.txt Il volume nell'unità C non ha etichetta. Numero di serie del volume: 0464-729A Directory di C:\temp 01/06/2007 19.36 0 foo2.txt 1 File 0 byte 0 Directory 4.808.515.584 byte disponibili

Use e.g. -f to check for the existence of the destination before possibly clobbering it.

Replies are listed 'Best First'.
Re^2: Renaming a group of files occassionally deletes some
by coldfingertips (Pilgrim) on Jun 01, 2007 at 18:51 UTC
    Sorry, the way it's worded is kind of strange. Is it saying that it will be clobbered if the file you're trying to rename to already exists in the directory?
      On Win32 and Linux, this test program shows that clobbering will happen.
      use strict; use warnings; my $file1 = 'file1.dat'; my $file2 = 'file2.dat'; for my $file ( $file1, $file2 ) { open my $fh, '>', $file or die; print {$fh} "Test data for file '$file'\n"; close $fh or warn; } rename $file1, $file2 or die;
      Output: Produces only one file, named `file2.dat`, containing "Test data for file1.dat"