I have files from a GoPro Fusion camera that represent images and movies. The filenames look like
GP (for “GoPro”) (two more letters of no particular significance) (a series of digits; maybe four or six digits) . (a period) (an extension)
Some of the extensions are common ones,
like JPG
, MP4
, and WAV
; others are uncommon.
Some example filenames are GPFR0000.jpg
, GPBK0000.jpg
, GPFR0000.gpr
, GPFR1153.MP4
, GPFR1153.THM
and GPBK142857.WAV
.
But the extensions aren’t relevant to this question.
For each image and movie there is a set of files
whose names have the same series of digits
right before the extension.
So, for example, GPFR1153.LRV
and GPBK1153.MP4
belong to the same set.
I want all the files from each set to be grouped in a directory
whose name is GP
followed by the series of digits.
For example, if I have
GPFR0000.jpg
GPBK0000.jpg
GPFR0000.gpr
GPFR0000.gpr
GPFR1153.LRV
GPFR1153.MP4
GPFR1153.THM
GPBK1153.WAV
GPBK1153.MP4
GPQZ142857.FOO
all in one directory, the outcome should be
GP0000\GPFR0000.jpg
GP0000\...
GP1153\GPFR1153.LRV
GP1153\GPFR1153.MP4
GP1153\...
GP142857\GPQZ142857.FOO
Would this be possible with a script (for Windows 10)? I found this (PowerShell) script by mousio at Recursively move thousands of files into subfolders windows, but it addresses a slightly different problem, and I’d like help adapting it to my requirements (I’m an artist, not a programmer).
# if run from "P:\Gopro\2018", we can get the image list
$images = dir *.jpg
# process images one by one
foreach ($image in $images)
{
# suppose $image now holds the file object for "c:\images\GPBK1153.*"
# get its file name without the extension, keeping just "GPBK1153"
$filenamewithoutextension = $image.basename
# group by 1 from the end, resulting in "1153"
$destinationfolderpath =
$filenamewithoutextension -replace '(....)$','\$1'
# silently make the directory structure for "1153 GPBK1153"
md $destinationfolderpath >$null
# move the image from "c:\images\1234567890.jpg" to the new folder "c:\images\1\234\567\890\"
move-item $image -Destination $destinationfolderpath
# the image is now available at "P:\Gopro\2018\1153\GPBK1153.*"
}
BLUE1742.FOO
andIRON1742.BAR
go together? … (Cont’d){
but no}
, so you’re missing part. (6) What is your question? (7) Why aren’t you asking the author of the script for help? … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … … Please do not respond in comments; edit your question to make it clearer and more complete.GPBK1153.*
moved into directory1153
. But, in your examples at the beginning of the question, you say that the directory name should beGP1152
. (And the fact that you switched from1152
to1153
confused me for a moment.) … (Cont’d)