Hello Again Programming Experts :),

Let me preface this by saying, I know absolutely nothing about writing scripts, or programming, so take it easy on me lol. Yall helped me out a ton last week with a batch file I needed assistance with and I greatly appreciate it!

Okay, here’s my scenario. Everyday we have 2 files that are automatically created and placed in a folder on a server. We are currently manually copying and pasting those 2 files to a different folder daily. We wanted the software to just export the file to correct location, but due to software limitations, it only exports to one place. Therefore we have to move it manually.
My question is, is there a script or something I can create to move the files daily for us?
I was going to use synctoy, but it keeps moving all the files in that folder, and we only need the 2 newest files to moved daily.

The files are always formatted like the following:
CIFmmddyyy.csv(example would be CIF04102017.csv the filename is always CIF followed by today’s date)
&
CIFmmddyyy.ctl(same as before but with a different extension)

I attached some snapshots for further clarification.

Thanks in advance yall!

6 Spice ups

Windows server? Try Robocopy as a scheduled task. You can use the MaxAge switch to only get new files.

2 Spice ups

Powershell to get the latest 2 files as you need to, and then either use ‘copy-item’ or robocopy.

What have you tried to far?

1 Spice up

set year=%date:~6,4%

set month=%date:~3,2%

set day=%date:~0,2%

move \CIF%month%%day%%year%.ctl \CIF%month%%day%%year%.csv

Add this to a batch file and then set up a scheduled task to run it when ever you want.

2 Spice ups

Correct, sorry forgot to mention it was Windows Server 2012. I have never used robocopy before. I will download it and see what I can do. Can you tell robocopy to move the two newest files daily?

Robocopy is a build in tool and ships with Windows. No need to download anything Robocopy "Robust File Copy" - Windows CMD - SS64.com

2 Spice ups

PowerShell would be something like this:

# List all the files in the directory
Get-ChildItem -Path C:\sourcefolder -File | 
# Pick all the files that have the current date in MMddyyyy format in their name
Where-Object name -like "*$(get-date -Format MMddyyyy)*" |
# copy each file into the destination folder
ForEach{Copy-Item -Path $_.FullName -Destination "C:\destinationfolder" -Verbose}
1 Spice up

You can create a script, or use Create Synchronicity, which is free and simple to use.

1 Spice up

Alrighty I was able to create a batch file. And it appears to be working. thanks for all your help! I am still looking into robocopy and powershell options so thanks for all your assistance!

Heres the batch file:

copy “Y:\CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%.csv” "H:\input"

copy “Y:\CIF%DATE:~4,2%%DATE:~7,2%%DATE:~-4%.ctl” "H:\input"

You’ve already gotten this figured out. So, my suggestion won’t have anything to do with this specific problem. However, I would recommend investing some time getting up to speed on PowerShell. I know some people here aren’t too big on making the jump from Command Line just yet, but since you mentioned you don’t have a lot of scripting experience, it sounds as if you’re starting from step 1 in either CMD or PowerShell. That being the case and since PowerShell is the MS-endorsed way forward, I’d say getting a firm grasp on PS would be at least a nice tool to have in your arsenal.

If you prefer videos, I recommend https://www.youtube.com/user/powershelldon/playlists , specifically the “PowerShell Tips, Tricks, and Snippets”.

If you prefer text, I recommend “Learning Windows PowerShell in a Month of Lunches” (also by Don Jones). Here’s a link for the 2nd Edition (PS ver. 3), and here’s one for the 3rd Edition (PS ver. 5).

1 Spice up

Thank you for this info! I agree I need to get up to speed with Powershell. I am always on youtube during lunch anyways, so this will be my go to!

Thanks again!

As a newer admin that works in Windows environments, I always shied away from robocopy. I don’t know why. I always just resort to PowerShell’s Copy-Item at this point. Are there any glaring advantages that robocopy has that PowerShell does not?

Your ignorance for Robocopy is like mine with PowerShell :wink: I have used Robocopy for years and am more familiar with it so I cannot say it is better. Powershell may actually be better so I may research that.

2 Spice ups

Copy-Item is fine for few items and good network.

Robocopy has just more options , especially if you copy large files, switches to pick back up and retry and such build in.

@scripting-guy

2 Spice ups

Robocopy is also multithreaded (configurable option) and has a lot of options for copying permissions, etc, I still use it for a lot of things.