I have a folder A with files 001.jpg, 002.jpg, etc
I also have a folder B with different files but with the same names; 001.jpg, 002.jpg, etc

I want to put all the files in the same directory - is there something that will automatically rename them or something so that they can all be in the same directory?

Thanks,

Dave

Dani AI

Generated

Two different goals need different, simple workflows — keep every file (avoid name collisions by renaming), or merge and dedupe (keep only unique/newer copies). Decide which is required before you start, and make a full backup of both folders first.

For keeping every file: add a short prefix/suffix that identifies the source folder, then move everything into one directory. Example PowerShell (edit the paths to match your machines):

Get-ChildItem 'C:\Path\FolderA' -File | ForEach-Object { Rename-Item $_ -NewName ("A_" + $_.Name) }
Get-ChildItem 'C:\Path\FolderB' -File | ForEach-Object { Rename-Item $_ -NewName ("B_" + $_.Name) }
Move-Item 'C:\Path\FolderA\*' 'C:\Path\Merged\'
Move-Item 'C:\Path\FolderB\*' 'C:\Path\Merged\'

For merging but avoiding duplicates by filename: move only files whose name does not already exist in the destination:

Get-ChildItem 'C:\Path\FolderB' -File |
  Where-Object { -not (Test-Path "C:\Path\FolderA\$($_.Name)") } |
  Move-Item -Destination 'C:\Path\FolderA'

For true content-based deduplication (same name but different content), compare hashes before moving:

$hashes = Get-ChildItem 'C:\Path\FolderA' -File | Get-FileHash -Algorithm SHA256 | Select-Object -ExpandProperty Hash
Get-ChildItem 'C:\Path\FolderB' -File | ForEach-Object {
  if(-not ($hashes -contains (Get-FileHash $_ -Algorithm SHA256).Hash)) { Move-Item $_ -Destination 'C:\Path\FolderA' }
}

Notes for and : pointed out renaming first as a tactic — that works for small sets but can be crude. , before deleting any numbered folder, confirm there are no unique files (compare sizes, timestamps, or use the hash method above), keep a backup copy, then remove the extras. Always test commands on a small sample directory first so you can undo mistakes.

Recommended Answers

All 3 Replies

Yes.
In folder one, select all/rt-click/rename
Enter an appropriate name (i.e. my vacation)
All will be renamed "My vacation001, etc.
Irfanview also has a batch rename utility.

commented: Thanks! +2

Ah great - I never knew about that!

My question is different. I have due to using System restore in Windows-XP, some folders in the same Directory but the folders are called say (Folder) and (Folder)(1) and (Folder(2).
Now as I have deleted OLDER restore points and in no need for such different folders, may I
1. Delete those with added numbers (1), (2)..etc or
2. Before doing that Can I copy contents of (Folder)(1) into (Folder) and (Folder(2) into (Folder)..etc..?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.