Bulk Move and Rename Files

I am a complete n00b when it comes to powershell. Sorry for what will probably be an easy question. I edit gopro videos in Adobe Premier. However the way Gopro names them it doesn’t import them into Adobe in order by modified time it does so by name and jumbles them all up. So what I would like to do is run a script that goes to my USERPROFILE\Desktop\GoPro\Script\ folder where I would have already copied all of my video files to. Then the script will move all of the .LRV, .THM, .JPG files and put them in a folder called LRV, THM, or JPG. Then it will take all of the .MP4 files and rename them with 1,2,3,4,etc appended to the begining of the original file name. So I should have something like 1.GOPR8768.MP4 2.GOPR8769.MP4. My understanding is the if you use the Modified time down to the seconds it should get them in the correct order. This is what I have so far:

set-location $env:USERPROFILE\Desktop\GoPro\Script
new-item -ItemType Directory “LRV”
move-item “.LRV" '.\LRV'
new-item -ItemType Directory “THM”
move-item "
.LRV” '.\THM'
new-item -ItemType Directory “JPG”
move-item “*.JPG” '.\JPG'

Any help is greatly appreciated.

Describing what you need is not a question. :wink: We do not write scripts on request. This forum is more to ask specific questions about code you wrote by yourself.
You could try to find some suitable scripts here: PowerShell Gallery or here: TechNet Gallery - resources for IT professionals.
Learn PowerShell: Microsoft Virtual Academy - Getting Started with Microsoft PowerShell.
Script requests: Microsoft Technet Script Center - Requests.

Do you really want to create the target folders every time you run your script? You will get errors then. You could continue with Get-ChildItem, Sort-Object, Foreach-Object and Rename-Item.

And please - format your code as code here in the forum. Thanks.

Of course this is really not a PoSH thing, as you can do this with DOS or VBScript as well. Yet as PoSH folks, of course we prefer using it. 8^}

As for …‘the if you use the Modified time down to the seconds it.’
Windows will always sort by name by default unless you explicitly specify an other criteria.

Anyway… there are lot’s of sources to point the ways to to do this sort of thing. Start with the MS PowerShellGallery.com
However, ostensibly, it’s just a matter of looping through the directories you created, and using a counter to use as a prefix to your filename(s) in the folder, looping through the files and add that counter number, of course sorting those files by LastWriteTime.

I apologize if it came across I was just asking someone to write it for me. I should have been a little clearer.

A. How do I rename the files by the time?
B. How do I create a counter and make that a variable that adds to the front of the file name?
C. Am I going about this correctly?

Also, what’s the tag for code? I didn’t see a button on the toolbar.

You should read the first 3 posts of this forum. There you’ll learn how to format code. The button name is “pre” (How to Format Code in the Forums)
You should learn the basics of Powershell. With the free of charge MVA video course I linked above it takes only a few hours and you will learn everything you asked and more. And I think it will pay off for you in the future. It is far beyond the scope of this forum to teach you how to use Powershell.
A. Rename-Item but what do you mean with by time? You can get information about a file by using its object properties

Get-Item -Path ‘Path to a example file’ | select-Object -Property *

B. You create variable and save an integer to it and increase with the increment you like.
C. That depends on what you expect.

Thanks dude, I’ll check out the video. I’ve been meaning to learn this so I appreciated the patience. Sorry about the tag question I was looking for one that said code.

The resources pointed to thus far are to help ensure your currently and needed future PoSH knowledge and your long term ability to wrap your head around it an use it for needs as they arise or even in future employment. You can also learn just be reading, and re-reading the PoSH help files…

Get-Help -name SomeCommandNameYouWantHelpAbout

and looking at the .ps1 files already on your system. There are bunches of them located here:

C:\Windows\System32\WindowsPowerShell\v1.0

Just make a copy of that and open in the PowerShell_ISE and review them. Heck even in the ISE< just hit CRTL+J to see a list of prebuilt snippets to review and understand.

Again, this is not something that is PoSH specific, as I said earlier. There are many ways to accomplish this use case, even in PoSH. It's just a matter of what you are comfortable with.

For example, if I was doing this, this below would be my approach, but that does not mean the below is the only way/absolute way of doing this. It's jus tone way of doing this. There are always more elegant ways of doing things.

    Clear-Host
    $NewFolders = 'LRV','THM','JPG' 

    $NewFolders | % {
    If ((Test-Path -Path "$env:USERPROFILE\Desktop\GoPro\Script\$_") -eq $false)
    {
        Write-Warning -Message "The UNC $env:USERPROFILE\Desktop\GoPro\Script\$_ does not exist. Creating the path."
        New-Item -ItemType Directory -Name $_ -Path "$env:USERPROFILE\Desktop\GoPro\Script\"
    }
    Else{"The UNC $env:USERPROFILE\Desktop\GoPro\Script\$_ already exists"} }

    $NewFolders | % { 
        "`n$_  **********`n"

        If (Test-Path -Path "$env:USERPROFILE\Desktop\GoPro\Script\$_")
        {
            $Count = 1

            ForEach($TargetFile in (Get-ChildItem -Path "$env:USERPROFILE\Desktop\GoPro\Script\$_" | Sort-Object LastWriteTime))
            {
                $Counter = $Count ++
                $NewFileName = ("$($Counter)" + '.' + "$($TargetFile.Name)")
                Rename-Item -Path $TargetFile.FullName -NewName $NewFileName -WhatIf
            }
        }
    }