comparing folders and copying missing files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

comparing folders and copying missing files

#1 Post by hiattech » 13 Jan 2015 12:37

Hi all,

I am trying to create a batch file that will compare two folders and copy any missing files from one file to another. I have a possible script but I'm getting something wrong with the variables (or maybe the whole script is wrong). Any suggestions?

Code: Select all

@echo off &setlocal
set "Mods=%appdata%\.minecraft\mods"
set "ServerMods=ftp:\\<serverIP>\mods"
set "Config=%appdata%\.minecraft\config"
set "ServerConfig=ftp:\\<serverIP>\config"
For %%a in ("%ServerMods%\*.jar") do if not exist "%Mods\*%%~na_recoded%%~xa" copy /y ServerMods\%%~na_recoded%%~xa Mods
For %%a in ("%ServerConfig%\*.cfg") do if not exist "%Config\*%%~na_recoded%%~xa" copy /y ServerConfig\%%~na_recoded%%~xa Config


There are also some subfolders in these that I wouldn't mind comparing as well if it's possible.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: comparing folders and copying missing files

#2 Post by Squashman » 13 Jan 2015 14:40


hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

Re: comparing folders and copying missing files

#3 Post by hiattech » 13 Jan 2015 16:22

Squashman wrote:You are trying to do this with FTP?
http://www.dostips.com/DtCodeBatchFiles ... lyNewFiles


Very close and it is partly because I forgot to include the rest of what I'm trying to do. What I need is for it to also compare existing files (and versions) to the current one and if it's not the same, replace it. I assume taking one of those scripts and adding a couple lines would take care of the problem.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: comparing folders and copying missing files

#4 Post by Squashman » 13 Jan 2015 18:07

hiattech wrote:
Very close and it is partly because I forgot to include the rest of what I'm trying to do. What I need is for it to also compare existing files (and versions) to the current one and if it's not the same, replace it. I assume taking one of those scripts and adding a couple lines would take care of the problem.

What is the criteria for that?

hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

Re: comparing folders and copying missing files

#5 Post by hiattech » 13 Jan 2015 19:00

Squashman wrote:What is the criteria for that?


Every so often, I update a mod. It will have the same name as the previous file. When a person runs the script, it will need check the file on the server and match size and possibly creation date or last modified date for comparison. I'm not sure what other properties to really check. The mods only change if I replace them with a new one and the server doesn't make any changes to the mod or config file as it runs.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: comparing folders and copying missing files

#6 Post by Squashman » 13 Jan 2015 19:08

Ugh. We have 3rd party software where I work that does this for us. Seems like it would be a pain to do this with the commandline ftp client and batch. FTP can play some weird tricks with timestamps.
You would be better of with some type of version control system.

hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

Re: comparing folders and copying missing files

#7 Post by hiattech » 13 Jan 2015 21:59

Squashman wrote:Ugh. We have 3rd party software where I work that does this for us. Seems like it would be a pain to do this with the commandline ftp client and batch. FTP can play some weird tricks with timestamps.
You would be better of with some type of version control system.


I'm ok with that. Suggestions? Any freeware options or cheap anyway?

hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

Re: comparing folders and copying missing files

#8 Post by hiattech » 14 Jan 2015 19:24

Squashman wrote:Ugh. We have 3rd party software where I work that does this for us. Seems like it would be a pain to do this with the commandline ftp client and batch. FTP can play some weird tricks with timestamps.
You would be better of with some type of version control system.


what's the name of the program you use and I can do some research on this?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: comparing folders and copying missing files

#9 Post by foxidrive » 14 Jan 2015 22:47

I'm just making convo here until Squashman can fill you in....

If you have a set of files and you need to keep them in sync on an FTP server,
then a simple way of checking the versions is to maintain a text file on your computer which lists the

c:\path\filename size date time

for each file - and every time the files are updated then a script can compare the text file to know which files are new,
and push them to the FTP server, and update the text file.

This will work if a single machine is updating the FTP files.

hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

Re: comparing folders and copying missing files

#10 Post by hiattech » 14 Jan 2015 23:22

Actually, the files would be downloading from the ftp to the computers that need updated.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: comparing folders and copying missing files

#11 Post by foxidrive » 15 Jan 2015 03:10

hiattech wrote:Actually, the files would be downloading from the ftp to the computers that need updated.

Do you control the updating of the FTP server files?

hiattech
Posts: 10
Joined: 13 Jan 2015 12:28

Re: comparing folders and copying missing files

#12 Post by hiattech » 15 Jan 2015 11:55

foxidrive wrote:
hiattech wrote:Actually, the files would be downloading from the ftp to the computers that need updated.

Do you control the updating of the FTP server files?


I do.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: comparing folders and copying missing files

#13 Post by Squashman » 15 Jan 2015 12:40

Because you are looking to roll this out to several people the software we use would be of no benefit to you nor would you want to pay the licensing for it.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: comparing folders and copying missing files

#14 Post by foxidrive » 15 Jan 2015 13:06

As you control the updating of the FTP server files, you can upload a text file with the path\filename of the changed files
on a schedule - and the users can use a script to check for that file and download the new ones on the same schedule.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: comparing folders and copying missing files

#15 Post by Squashman » 15 Jan 2015 13:16

foxidrive wrote:As you control the updating of the FTP server files, you can upload a text file with the path\filename of the changed files
on a schedule - and the users can use a script to check for that file and download the new ones on the same schedule.

That is the great idea. A lot better than using the FTP sync in the library.

Post Reply