My network directory file synch batch file thing

AI Thread Summary
A user developed a batch file solution to synchronize MP3 directories between a laptop and a home theater PC (HTPC) without overwriting existing files. The setup involves mapping the HTPC's MP3 drive to the laptop's E drive, with music files stored on the C drive of the laptop. The challenge was to copy only new files from the C drive to the HTPC while maintaining the same directory structure. The batch file utilizes a FOR statement to check for existing files and create directories as needed. It generates a secondary batch file to handle the copying process and cleans up temporary files afterward. Additionally, the discussion touches on using Subversion for version control in collaborative environments, although it is noted to be more complex than the proposed batch file solution. An alternative method using Linux commands is also mentioned for similar synchronization tasks.
aychamo
Messages
375
Reaction score
0
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 that's 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) doesn't 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 doesn't 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 let's 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
 
Computer science news on Phys.org
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.
 
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.

[edit] Subversion could work, but a hassle because you need to commit your changes.
 
In my discussions elsewhere, I've noticed a lot of disagreement regarding AI. A question that comes up is, "Is AI hype?" Unfortunately, when this question is asked, the one asking, as far as I can tell, may mean one of three things which can lead to lots of confusion. I'll list them out now for clarity. 1. Can AI do everything a human can do and how close are we to that? 2. Are corporations and governments using the promise of AI to gain more power for themselves? 3. Are AI and transhumans...
Thread 'ChatGPT Examples, Good and Bad'
I've been experimenting with ChatGPT. Some results are good, some very very bad. I think examples can help expose the properties of this AI. Maybe you can post some of your favorite examples and tell us what they reveal about the properties of this AI. (I had problems with copy/paste of text and formatting, so I'm posting my examples as screen shots. That is a promising start. :smile: But then I provided values V=1, R1=1, R2=2, R3=3 and asked for the value of I. At first, it said...
Back
Top