Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On windows, how can I set up a mechanism so that when I move a file into a directory where a file with the same name already exists, the new file is renamed randomly (or to <>.ext)?

Use case: I'm browsing cheezburger, drag and drop an image into a folder. Problem: all of them are named i.chzbgr.jpg => conflict. Windows offers to replace or not move, not even autorename ...

share|improve this question
Yeah, windows does offer to keep both files. Not on an English Windows, but it says something like "Move, but keep both files", the new file will get the name "conflictingname(2)". – Martin May 27 '13 at 21:46
@Martin: Not always. Copy a file to a dir. Try to copy/move the same file and Windows will ask to either: 1) Copy and Replace, 2) Don't copy, 3) Copy, but keep both files. However, now drag an image from within Firefox to a dir. Now drag it again to overwrite. You'll see options 1 and 2, but not 3. On IE it works somewhat, because when you drag/drop it copies from the Temporary Internet Files dir, so it's like just another normal copy operation. Of course, with IE seems one can't drag/drop hyperlinked images (I tried the gravatar above and it created an Internet Shortcut instead.) – Karan May 28 '13 at 0:01
You're right, never realized that before, weird. – Martin May 28 '13 at 0:32

Not a perfect solution, but I found and modified a script that monitors a folder for new files, when it detects a new file it automatically renames it with a random number. Copy paste the following and save it as a .ps1 file. Run it from powershell console or cmd. (make sure to enable running of ps scipts).

$folder = 'Q:\Test\# Downloads'  # <-- Change as desired
$filter = '*.*'
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{
 IncludeSubdirectories = $false        
 NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
$onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
 $path = $Event.SourceEventArgs.FullPath
 $name = $Event.SourceEventArgs.Name
 #$changeType = $Event.SourceEventArgs.ChangeType
 #$timeStamp = $Event.TimeGenerated
 if( $name -imatch "stop")
    Unregister-Event -SourceIdentifier FileCreated;
    write-host "Monitoring stopped.";
    $count=$(Get-Random -minimum 1 -maximum 999999);
    $p = Split-Path "$path" -Parent;
    $newName = "$p\$count-$name"
    while(test-path $newName)
        $count=$(Get-Random -minimum 1 -maximum 999999);
        $newName = "$p\$count-$name";
    Move-Item $path -Destination $newName -Force -Verbose

Adding a file named "stop" to the folder stops the monitoring.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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