# Divide photos into folders

Hi everyone, I have a folder with a lot of photos. I would like to be able to divide them into subfolders that have as their name the date of acquisition of the photos. Is it possible to have a powershell?

Thanks.

Absolutely possible. Here’s where I would start. Do Get-Help on the following:

Get-Item

Get-ChildItem

Get-ItemProperty

Copy-Item

New-Item

Come back with some code and maybe I can help you out.

Hi, I have this:

gci | ? {-not $.psiscontainer} | % {$.creationtime.tostring(‘yyyy-MM-dd’)} | sort -unique | % {new-item -type directory $_}$files = gci | ? {-not $_.psiscontainer}$folders = gci | ? {$_.psiscontainer} foreach ($file in $files) {foreach($folder in $folders) {if($file.creationtime.tostring(‘yyyy-MM-dd’) -eq $folder) {move-item$file.fullname -destination $folder}}} It work fine, but it doesn’t use the date of acquisition What is the “date of aquisition”? File objects have the following date properties: ## Name CreationTime CreationTimeUtc LastAccessTime LastAccessTimeUtc LastWriteTime LastWriteTimeUtc Is it one of these? [quote quote=274149]What is the “date of aquisition”? File objects have the following date properties: Name —- CreationTime CreationTimeUtc LastAccessTime LastAccessTimeUtc LastWriteTime LastWriteTimeUtc Is it one of these? [/quote] In windows 10 (Italian) I can sort the files by date, creation date and acquisition date. Only the date of acquisition shows the true date the photos were taken. Date the picture was taken is metadata: https://devblogs.microsoft.com/scripting/use-powershell-to-find-metadata-from-photograph-files/ [quote quote=274158]Date the picture was taken is metadata: Use PowerShell to Find Metadata from Photograph Files <iframe width="600" height="338" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="“Use PowerShell to Find Metadata from Photograph Files” — Scripting Blog" src="https://devblogs.microsoft.com/scripting/use-powershell-to-find-metadata-from-photograph-files/embed/#?secret=puQCzcL6sq" data-secret="puQCzcL6sq" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" data-mce-fragment="1"></iframe> [/quote] Hi, could you modify my powershell to make it work? I am just starting out! [quote quote=274158]Date the picture was taken is metadata: Use PowerShell to Find Metadata from Photograph Files <iframe width="600" height="338" style="position: absolute; clip: rect(1px, 1px, 1px, 1px);" class="wp-embedded-content" sandbox="allow-scripts" security="restricted" title="“Use PowerShell to Find Metadata from Photograph Files” — Scripting Blog" src="https://devblogs.microsoft.com/scripting/use-powershell-to-find-metadata-from-photograph-files/embed/#?secret=puQCzcL6sq" data-secret="puQCzcL6sq" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" data-mce-fragment="1"></iframe> [/quote] In the folders I have .jpg and .raw files. From the .raw files I don’t think you can find the date from the metadata. $folder = \\path\to\photos
Get-ChildItem -Path $folder -Filter *.jpg | ForEach-Object { # Get date in custom format$dir = get-date -Date ($_.CreationTime) -Format 'yyyy-MM-dd'$dest = Join-Path -Path $folder -ChildPath$dir

# Create folder based on custom format and move .jpg,.cr2 files
IF (!(Test-Path -Path $dest)) { New-Item -ItemType Directory -Path$dest -ErrorAction SilentlyContinue}
Move-Item -Path $_.FullName,($_.FullName -replace '\.jpg$','.cr2') -Destination$dest
}


Hi, thank you. As I said, for each photo I have 2 files… namephoto.jpg and namephoto.cr2. Is it possible to move all this files?

My edit should work for both file formats

Hi, thanks for the script. I wanted to ask you if I have to add the folder where it finds the files or if it is enough to put the script in the working folder.

Thank you