4

I know this has been touched upon in this post, but I was hoping for some additional clarification about this.

Currently, with the Dropbox Core API, there doesn't seem to be a way to track files that have been renamed. For example, if you're using the API to sync a Dropbox app_folder with a local application directory. You rename the file on the Dropbox side and then call delta to see how you should update your local application directory, you're returned two entries...

array(
    0 => '/somefile.txt',
    1 => null
),
array(
    0 => '/somefile-renamed.txt',
    1 => array(
        'revision' => 343
        'rev' => 'd90se4c661'
        'thumb_exists' => false
        'bytes' => 1263
        'modified' => 'Tue, 09 Apr 2013 19:06:39 +0000'
        'client_mtime' => 'Tue, 09 Apr 2013 18:43:06 +0000'
        'path' => string '/somefile-renamed.txt'
        'is_dir' => false
        'icon' => 'page_white_text'
        'root' => 'app_folder'
        'mime_type' => 'application/octet-stream'
        'size' => '1.2 KB'
    )
)

For each array returned, the first element is the file that requires an update and the second element is the file metadata info. If the second element is null, you should delete your local version (and anything under it, if it's a directory) of that file.

So, in the above example, it's telling you to delete the first file and upload this completely new file. Unfortunately, there's no way to track that this new file that you have been told to create was actually just the renamed version of the file you're being told to delete. From your application's perspective (the non-Dropbox side), it just looks like a strait delete and a new file coming in.

This can be problematic if you're storing the data in these files elsewhere (like in a database) and you need to update the record instead of creating a new record and deleting the old one.

Is there some accepted way to track file association after a rename? I can't seem to find a way to do it using metadata, delta or revisions.

Community
  • 1
  • 1
CVEEP
  • 441
  • 4
  • 12

4 Answers4

3

I don't think Dropbox knows the difference between renaming and deleting/adding a file. Every time I rename a file in a local Dropbox folder on my hard drive, I momentarily see the old file re-appear with a "deleted" icon overlay, while the new file shows an "uploading" icon.

You might be able to detect renames with reasonable accuracy by comparing the contents of files that have been deleted and created (perhaps also comparing timestamps), but even then it's iffy.

etodd
  • 483
  • 1
  • 3
  • 8
  • Yeah, at one point I was trying to determine this by storing a hash of the file contents but it felt seriously hackish so I [backed away](http://www.youtube.com/watch?v=2iE4uEsaBF0&feature=youtu.be&t=10s) from that solution. – CVEEP Apr 11 '13 at 14:30
  • The API has a `move` method: https://www.dropbox.com/developers/core/docs#fileops-move Do with it what you will =) – Rudie Dec 23 '13 at 18:53
0

Unfortunately the only way to track file renames through the Dropbox API is to store a content hash of every file you need to track.

Here is how I detect renames:

  1. Call /delta until Dropbox tells me to back off.

  2. Now that I have a complete list of changes, filter this list of files into:

    • updated files
    • deleted files
    • new files
  3. Read the contents of each new file and hash its contents.

  4. For each deleted file, look up the hash you've stored then check this against the hash of each new file. If two hashes match, then the file has been renamed.

N.B. This technique only works if you can update a file's hash the moment it's modifed by the user. This is possible if your app uses Dropbox webhooks and the user doesn't edit then move files around while offline.

I hope Dropbox eventually exposes file renames through their API.

0

You can find a renamed file since the client_mtime and filesize rename unchanged. It's kind of a hack, but easier than checking hashes.

Brian Ruff
  • 137
  • 1
  • 10
-1

In dropbox if you have a file and you want to rename it, then simply follow this logic it will solve your problem.

  1. Get Name of File and Change it and store the change name in string variable.
  2. Keep Parent Path of the original File.
  3. Move File to other place with the change Name get from String variable.
  4. Now move the File back from new place to old place,
                 How to do it Programatically,
  Entry global_file;//assign any file to it 
  String FilePath=global_file.path;
  String parent_path=global_file.parentPath();//Keep parent path 

    String ChanageName= "Your changed Name";
    parent_path=parent_path+""+ChanageName; //setting path for renamed file to move to its original place.


    Entry RenamedFile    = mApi.move(FilePath, "/"+ChanageName);  //move to new place "/"
    Entry MoveRenameFile = mApi.move(RenamedFile.path,parent_path); //move to previous location
Pir Fahim Shah
  • 10,505
  • 1
  • 82
  • 81
  • To rename a file, just use the Move API, and provide the original path and the new path. It's just like renaming a file on Linux. – Lai Xin Chu Nov 20 '14 at 02:40
  • The two negative voters came from windows and they do not know what rename was all about..!! this worked great for me so up voting. – Clain Dsilva Sep 27 '15 at 07:31