# My network directory file synch batch file thing

1. Aug 24, 2004

### aychamo

My network directory file synch batch file thing :)

Hey guys

I had been looking for a nice cheap easy to use program to sync two of my mp3 directories. This is what I did:

Here is my setup:
My HTPC .mp3 drive is mapped to my laptops' E drive.
I always download my songs onto my computer (C drive) and keep them on my C drive as I travel with my laptop.

My problem:
I maintain a \Artist\Album\Songname.mp3 directory structure on my C drive and I mimic the same directory structure on my HTPC for my music there. It was a pain if I would get a new artist or album on my C drive and then have to copy it over. Also, i couldn't find a command in windows to copy all my *new* files over but not overwrite the old ones (copying so many gigs of data over the network took a while).

My solution:
I wanted a program that would only copy files from my C drive to my HTPC's .mp3 drive (mapped to E on my computer) that did not exist on the HTPCs harddrive. I found some programs, etc, but they were all  or I couldn't automate it.

Turns out, it was pretty simple to accomplish. I had to reach back into the old days of batch file programming and pull out the FOR statement.

I then encountered a problem if a directory did not exist, but I solved that and had it create directories and then copy new files over. It's all in the batch file, it should be fairly readable....... here it is if anyone needs it:

A quick note: To keep it clean, I have my batch file generate a 2nd batch file that it needs, and the .mp3 list.. and it cleans them up afterwards. I added the generation thing in last so thats why you see the echoing of REM'ed statements to a batchfile you'd never get to read :-)

PHP:
@echo off

echo @if "%%3"=="" goto dothedir>copyit.bat
echo @if "%%3"==".bat" goto end>>copyit.bat
echo @if "%%3"==".lst" goto end>>copyit.bat
echo @echo off>>copyit.bat
echo if not exist %%2 goto notexists>>copyit.bat

echo REM if the third parameter (extesnion) is blank, it's a dir so jump down>>copyit.bat
echo REM there, ..  if the 2nd paremeter (destination) doesnt exist, then copy it!>>copyit.bat

echo REM this is for if the destination does exist>>copyit.bat
echo goto end>>copyit.bat

echo REM if the destination doesnt exist, it comes here, copies first to 2nd>>copyit.bat
echo :notexists>>copyit.bat

echo echo copy %%1 %%2>>copyit.bat
echo copy %%1 %%2>>copyit.bat
echo goto end>>copyit.bat

echo REM if the passed file is a directory, come here, check it if exists>>copyit.bat
echo REM if it does exist, end, if it doesn,t jump to the part to maek it>>copyit.bat
echo :dothedir>>copyit.bat
echo @echo off>>copyit.bat
echo if not exist %%2 goto makethedir>>copyit.bat
echo goto end>>copyit.bat

echo REM this makes the directory, and lets you know>>copyit.bat
echo :makethedir>>copyit.bat
echo mkdir %%2>>copyit.bat
echo echo Created directory: %%2>>copyit.bat
echo goto end>>copyit.bat

echo :end>>copyit.bat

echo Generating dir list
dir /s /b /og *.*>mp3.lst

echo Executing FOR statement
for /F "delims=\$" %%i in (mp3.lst) do @call copyit.bat "%%i" "e:\media%%~pnxi" %%~xi

echo Cleaning up ..
del copyit.bat
del mp3.lst
echo Done!
exit

2. Aug 24, 2004

### Goalie_Ca

Developpers and group projects often have the same issue. How to keep a common codebase/document base while so many different users and different computers are accessing it. Well, there's a solution! :surprise:

http://subversion.tigris.org/

It might be a little more complex then typical windows world stuff, but it gets the job done, and quite nicely for devs. It will work with text or binary files.

3. Aug 24, 2004

### dduardo

Staff Emeritus
In Linux/Unix you could setup a cron job that executes this command:

cp -uRp <source directory> <destination directory>

u = only overwrite the file if the timestamp is different (This means the file has been modified)
R = copy recursively
p = preserve file attributes (like the time stamp)

You would do this on both computers at different times. If you wanted to you could setup cygwin to do this.

 Subversion could work, but a hassle because you need to commit your changes.