Task Scheduler - how to move specific files to another location?

Sonny 1 Reputation point
2021-12-28T22:10:05.017+00:00

Hi,

I would like to automatically move files from my Download folder to a specific folder. They are Excel items that I download and the names only differ in the date in the name. For example:

Dummy holdings 20211222.xlsx

Dummy holdings 20211221.xlsx

Dummy holdings 20211220.xlsx

So the name at the beginning is always the same but the date changes it.

I have other stuff in that folder that I don't want to move.

I know you can use a program like Task Scheduler but I don't know how to modified the scripts available online that lets me target specific files.

@Echo off

set X=7

set "source=C:\someone\Downloads"

set "destination=C:\Temp\Copy

robocopy "%source%" "%destination%" /mov /minage:%X%

exit /b

Is there a way to do this please?

Thank you

S2

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. DaveK 1,871 Reputation points
    2021-12-28T23:45:36.107+00:00

    You can most certainly do what your asking with powershell as I do very similar myself using task scheduler. I’m not at my Pc can’t provide code but if you take a look at examples online searching for:

    Get-Childitem filename filer

    And

    Move-Item

    You should be able to do something like:

    Get-childitem -path c:\someone\download -filter “ Dummy holdings*.xlsx” | Move-Item -Destination “c:\temp\copy\” -force

    0 comments No comments

  2. Limitless Technology 39,916 Reputation points
    2021-12-30T10:46:00.42+00:00

    Hello Sonny

    Thank you for your question and reaching out.

    I can understand you want to move files using command from one folder to another.

    I would suggest you can use below simple move command which should be serve your purpose.

    move "C:\data\Dummy holdings*.xls" D:\Backup\

    Hope this answers your question :)


    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

  3. MotoX80 36,291 Reputation points
    2021-12-30T15:35:13.373+00:00

    If you're going to run it via the task scheduler, you will want to have it create a transcript so that you can see what it did and any errors that it might encounter.

    Start-Transcript -Path ("C:\temp\{0}-{1}-FileMover.txt" -f $env:USERNAME, (get-date -format "yyyyMMdd-HHmmss" ))            # This is your log file 
    $files = Get-ChildItem -Path 'c:\someone\downloads' -file -filter 'Dummy*'
    "Moving these files."
    ($files).Name 
    $files | Move-Item -Destination 'C:\temp\copy' 
    Stop-Transcript
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.