11/08/2012

Fix a Bug of Dropbox Camera Upload


I, as a senior user of the feature of Dropbox, especially the feature of Camera Upload, cannot endure the hundreds of photos with such name 2002-12-08 12.00.00-1-2.jpg in my Camera Uploads fold.

Long time ago, I suppose that its the bug of MIUI, a Chinese Mobile OS based on Android. But later I realized the bug didn't relate to the OS because the error-name bug still exist with several versions of MIUI, and even with the native Android OS. So I search in the official forum of Dropbox and thanks for Lihiniya(https://forums.dropbox.com/topic.php?id=91810#post-504267). The problem is the app that cannot provide right EXIF information for their photos. So, I decide to resolve this problem by modify the wrong name. I use the modified time of photo because it's the nearest time of the right time.

I write the program by Autohotkey. Basicall, travel all files in the Camera Uploads fold, and figure out the files needed rename, then process each one. I spend two hours to write this little thing, because I haven't wrote AHK code long time.

The tutor: open the exe file, press Win key & 2, input your Camera Uploads fold path, Enter, it will modify your wrong name files automatically. PS: It will warn you by display the file path if one file cannot be renamed.

The link of exe file: https://www.dropbox.com/s/gpthiuylklui3x0/fixDropboxCameraUploadTimeBug.exe

The link of ahk file: https://www.dropbox.com/s/wnl6sg13qnc47e4/fixDropboxCameraUploadTimeBug.ahk

The source code:
#2::
   InputBox, photoPath, Please Input the PATH of Camera Uploads , like:D:\Dropbox\Camera Uploads, , 300,128   ;input setting
   if ErrorLevel
      MsgBox, Exit,88~
   else
   {
      photoPath := RegExReplace(photoPath,"\\$","")   ;删除末尾多余的\ | Delete the extra \ in the end of the path
      ;MsgBox, You entered "%photoPath%"
      Loop, %photoPath%\*.*, 0, 1    ;Loop the input fold
      {
          ;MsgBox, 4, , Filename = %A_LoopFileFullPath%`n`nContinue?
          tempFile = %A_LoopFileFullPath%
          FoundPos := RegExMatch(tempFile, "2002-12-08 12.00.00")   ;detect one file is a file with time bug
          if FoundPos
          {
             ;msgbox %tempFile% %FoundPos%
             renameOneFile(tempFile)   ;process one file
          }
      }
   }
return

renameOneFile(filePath)
{
   FileGetTime, modifiedTime, %filePath%    ;get the modified time
   ;tempFileFullPath := RegExReplace(modifiedTime,"(\d4)(\d2)(\d2)(\d2)(\d2)(\d2)","$1-$2-$3 $4.$5.$6")
   tempFileFullPath := RegExReplace(modifiedTime,"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})","$1-$2-$3 $4.$5.$6")    ;convert only number time to the Dropbox format file name
   tempFileFullPath := RegExReplace(filePath,"(?<=\\)[\d-\. ]{19,}(?=.[a-z]{3})",tempFileFullPath)  ;add path
   ;msgbox %filePath%`n%tempFileFullPath%
   FileMove, %filePath%, %tempFileFullPath%, 0   ;change the file name
   if ErrorLevel
     msgbox %filePath%      ;msg the file path that cannot be changed for user
   return
}