Autorename files with identical names when dropping in directory
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 ...
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.";
Exit(0);
}
else
{
$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.
I know it's a 3 year old thread, but maybe somebody (like me) will find this useful.
Make a small folder such as "___Stage" somewhere simple, perhaps at the root of your photo or music storage.
Open that folder in a separate small instance of [windows] explorer on the desktop somewhere. Make it just large enough in visual size to hold a single file in view -- I set about 2 inches square, and set the view mode to large icon to make it big enough to grab without being too accurate.
Drag and drop your internet/firefox/chrome/etc. file to the view pane of that folder.
Drag and drop AGAIN from this folder to your intended destination folder. This will be considered a directory to directory MOVE, which will unlock that magic option #3 "Move new file with (x) appended to rename and keep both files"
Viola.
I tried above just dragging to desktop, but this leaves the file still on the desktop unless you kill the "+" by holding the shift key (or shift mouse button if you have a multibutton mouse set up that way) For some reason win7 considers the desktop different than a directory.
I know this is cludgy, but you never have to take your hand off the mouse, or hunt down the naming conflict and rename it properly.
If you can't stand 01.jpg, 01(1).jpg, 01(2).jpg you'll have to rename them individually. I cannot fathom why win7 removed the #3 option functionality from the COPY option yet includes it in the MOVE option.