Robycopy script to move files misses newly added files

Hello, new to powershell. Currently i am using powershell to write files from a temporary folder to a different drive. I would like to see about adding another script to count files in temp folder, if count exceeds (x) then move (y )= amount of files to be moved to temp folder z.
I am thinking with moving files to a secondary temp folder, i could then use a script to write from that folder to a different drive. Using windows, any help would be greatly appreciated. I hope this made sense.

Welcome to the forum. :wave:t3:

That sounds like a nice little finger exercise. So what is your question? Please share your code (formatted as code) and explain what’s not working as expected or what issues you have with it.

Please keep in mind … this forum is for scripting questions rather than script requests. We do not write customized and ready to use scripts or solutions on request.

We actually expect you to make an own attempt at the first place to get your task done or to solve your problem. If you have done so already please document here what exactly you have done and show your code. Then we probably might be able to help you step further.

Thank you for getting back to me. I will attempt to finish creating my script. I will get back with you :blush:

It does not have to be finished. Just post what you have and explain what you’ve got stuck with. :man_shrugging:t3:

Thank you for getting back to me. (that was supposed to be in my original reply to you.)
I made this script to move large finished files from the NVME temp folder to a local HDD.

Over time the script seems to build up unmoved files, it will even go into wait for multiple hours with files in the folder that are eligible for moving. At this point I stop the script and restart it, then it works again for a while. I am putting a new file in this temp folder every ~8 min, and my move speed is a little faster than that, so I should be able to keep this folder from growing in size.

robocopy N:\finished_plots O:\ /J /MOV /XF *.plot.tmp /MOT:1

Hmmm … until now there is no PowerShell code yet. It’s a robocopy comannd line with arguments and options. :man_shrugging:t3: Is that all you have in your script?

What exactly does that mean?

What exactly does this mean? How do you know that it does “into wait”?

Please keep in mind: We cannot see your screen and we cannot read your mind. You will have to explain as detailed as needed to understand your situation.

Regardless of that:
A general tipp when you post more than one line of code or console output or error messages:
When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( </> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

How to format code in 1 <---- Click :point_up_2:t4: :wink:

( !! Sometimes the preformatted text button hides behind the settings gear symbol. :wink: )

Thank you for your patience, as I am a new to this. The robocopy running in PowerShell is the entire script that I came up with. It is only one line currently. If there is a better way to do this in PowerShell I’m more than open to starting over.

Run continuously
Monitor folder on N: for eligible files (I am not trying to look for changes, I want to move all that are not excluded, regardless of when they were created in the folder.)
Move any non excluded file types to the target drive (currently the O drive )
Repeat, if no eligible files detected wait one minute and repeat.

The script does work, it begins moving one file at a time when I execute it. (Example, there might be 5 files ready at execution), and while those 5 large files are being moved the system added additional files to the temporary folder. Frequently the script does not act on those new additional files that should be moved.

At completion of the move of the above 5 files, I would like the script to look at the folder and move any other files that are not excluded. (excluded are *.plot.tmp files). Currently the script will continue checking every one minute until an additional new file is detected, but it will only then move the single new file, leaving behind other files that were added to the folder during the move phase.

normal wait looking for changes in folder

this is what I get when it gets stuck. When this happens I have to stop the script and restart it.

This is the script I am using, it is a robocopy command in powershell. I have re-inserted the script using the correct code option, sorry for the incorrect entry type.

robocopy N:\finished_plots O:\ /J /MOV /XF *.plot.tmp /MOT:1

Thank you for the great questions and feedback.

Please do not post images of code ir error messages. Instead post the plain text and format it as code. :point_up:t3:

Again: There is actually no PowerShell script. There’s not a single line of PowerShell code. I don’t have any idea why robocopy does not do what you expect and you may be better of in a MSFT forum.

How big are the files you’re moving around? Or how many do you put there from one minute to the next? Of course I cannot reproduce your situation and when I tested it with a few normal sized files for a few minutes it just worked as expected. :man_shrugging:t3:

You posted only a part of the robocopy output. Does the rest of it maybe give a hint why it does what it does?

Define better! :wink:

That’s usually the biggest challenge when you want to have it robust and reliable.

You could use an infinite loop

Please always read the help for the cmdlets you’re about to use completely including the examples to learn how to use them.

Another option would be to use a FileSystemWatcher.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.