1

I have a MySQL database that holds the file names and folder locations of a lot of files. I was wondering if I rename a file (just through windows explorer), is there any way to automatically sync that change to the database? Same for if I add a new file or move a file to another folder.

abney317
  • 7,760
  • 6
  • 32
  • 56

1 Answers1

1

"Automatically" is a strong word in this case.

You could have a cron job that runs a script to scan the filesystem and adjust the contents of the database.

Matt
  • 5,315
  • 1
  • 30
  • 57
  • Oh, you're on windows. No cron unless you setup something like cygwin. At some point I'd question what you're trying to accomplish. – Matt Feb 13 '13 at 01:39
  • Really just looking for a way to where I don't have to go update the database whenever I change a file name or add a new file. Don't like having to type in the file names twice. – abney317 Feb 13 '13 at 01:44
  • Fair enough. But why are you tracking them in the database anyway? What's the end goal? Whatever you're doing with the data, why not just read it directly from the filesystem instead of the DB? There is a way to schedule PHP tasks with windows also if you want to try to keep the filesystem and DB in sync: http://stackoverflow.com/questions/295386/how-to-run-a-php-file-in-a-scheduled-task-windows-task-scheduler – Matt Feb 13 '13 at 01:46
  • It's counting the number of downloads on the files – abney317 Feb 13 '13 at 01:48
  • 1
    In that instance, could you do something like track the number of downloads on the md5sum of the file? If I try to download directory/file.txt in php you could check the md5() of that file and check if that md5 already exists in the db. If not add it with a count of 1 otherwise increment. That way it doesn't matter where the file is located. – Matt Feb 13 '13 at 01:49
  • I suppose reading the file names straight from the folders and using md5 would work, but looking at a list of files with download counts and checking the md5 on all of them might be pretty slow (I think). – abney317 Feb 13 '13 at 06:54