My network directory file synch batch file thing

In summary, this guy syncs his music between his computer and his HTPC by using a batch file and a directory. He had to use old-school batch file programming techniques to do this because Windows doesn't have a command to do it.
  • #1
aychamo
375
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
  • #2
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
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.
 

1. What is a network directory file synch batch file?

A network directory file synch batch file is a type of computer file that contains a set of instructions for synchronizing files in a network directory. It allows for automatic updating and syncing of files across multiple devices or locations.

2. How does a network directory file synch batch file work?

A network directory file synch batch file works by using a set of commands to compare files in the network directory and determine which files need to be updated or synced. It then carries out the necessary actions to ensure that all files are consistent and up-to-date.

3. What are the benefits of using a network directory file synch batch file?

Using a network directory file synch batch file can save time and effort by automating the process of syncing files across a network. It also helps to ensure that all files are consistent and up-to-date, reducing the risk of errors or discrepancies.

4. Are there any potential drawbacks to using a network directory file synch batch file?

One potential drawback is that if the batch file is not properly configured or maintained, it may result in unintended changes or deletions to files. It is important to regularly review and update the batch file to avoid any potential issues.

5. Can a network directory file synch batch file be customized?

Yes, a network directory file synch batch file can be customized to fit the specific needs and preferences of the user. Different commands and parameters can be added or modified to tailor the syncing process to the user's requirements.

Similar threads

Replies
16
Views
2K
Replies
14
Views
2K
  • Programming and Computer Science
Replies
10
Views
4K
  • Computing and Technology
Replies
22
Views
2K
  • Programming and Computer Science
Replies
11
Views
1K
  • Computing and Technology
Replies
1
Views
1K
  • Programming and Computer Science
3
Replies
81
Views
5K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
5K
  • Computing and Technology
Replies
10
Views
3K
Back
Top