You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

outsidecoder's avatar
outsidecoder
Helpful | Level 5
7 years ago

Automatically Deleting Files After X Days - General Data Protection Regulation May 2018

Hi there,

I'm using the Java SDK 3x (API v2) and I'm looking for pointers/code to automatically delete files that are X number of days old.  There is post on this forum which is doing this in python however not seen anything for Java.  I can't use any third party tools due to the context of my client's application.

 

With the European GDPR I feel this feature should be in built into the uploading process, that is defining a 'retention schedule' for all the files.  If this feature is going to be implemented will it be in time for when the Eurpoean GDPR  is active in May 2018?

 

Best regards and thanks for any assistance :)

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Thanks for the post! Dropbox doesn't offer a way to do this automatically via the API. I'm sending this along as feature requests for created and modified times for folders, as well as a native way to have Dropbox automatically delete files after a certain amount of time. I can't promise if/when these would be implemented though.

    • LukFromTheSky's avatar
      LukFromTheSky
      New member | Level 2

      Hello Greg,

       

      Was there any progress on that?

       

      Thanks,

      Luk

    • outsidecoder's avatar
      outsidecoder
      Helpful | Level 5

      So created a quick bit of code to delete files older than X days but its very rough and hasn't been tested properly.  It doesn't get round the issue of dates of folders, nor does it get round the issue of not knowing the creation date.  Comments welcomed as there must be a better way than this?

       

         enum MODIFIED_DATE_TYPE {
              SERVER_MODIFIED_DATE, CLIENT_MODIFIED_DATE;
          }
      
          private long deleteFilesOlderThanXDays(long numDays, MODIFIED_DATE_TYPE TYPE) throws DbxException {
              //ALPHA - add protection against going above long.MAXIMUM
              long numberFilesDeleted = 0;
              ListFolderBuilder listFolderBuilder = client.files().listFolderBuilder("");
              ListFolderResult result = listFolderBuilder.withRecursive(true).start();
      
              while (!result.getHasMore()) {
                  if (result != null) {
                      for (Metadata entry : result.getEntries()) {
      //                    System.out.println("Analysing: " + entry.getPathLower());
                          if (entry instanceof FileMetadata) {
                              Date dateOfFile;
                              switch (TYPE) {
                                  case CLIENT_MODIFIED_DATE:
                                      dateOfFile = ((FileMetadata) entry).getServerModified();
                                      break;
      
                                  case SERVER_MODIFIED_DATE:
                                      dateOfFile = ((FileMetadata) entry).getClientModified();
                                      break;
                                  default:
                                      throw new AssertionError();
                              }
                              //Check to see if the current file is too old
                              if (getDaysBetween(new Date(), dateOfFile) > numDays) {
                                  this.deleteFile(entry.getPathLower());
                                  numberFilesDeleted++;
                              }
                          }
                      }
                      if (!result.getHasMore()) {
                          return numberFilesDeleted;
                      }
                      try {
                          result = client.files().listFolderContinue(result.getCursor());
                      } catch (DbxException e) {
                          //ALPHA - TIDY UP HERE.  CATCHING or THROWING??? - GDPR - Note what you're logging
                          //  log.info("Could NOT get listFolderContinue");
                      }
                  }
              }
              return numberFilesDeleted;
          }
  • tuancrab's avatar
    tuancrab
    New member | Level 2

    It is super easy to have a Google script code with Chatgpt to delete specific filetypes, after x days ... and other filtering conditions as you like: notification to email after completion, trigger runs everyday, week or more when you use Google Drive. I'm still not sure how to do that with Dropbox.

    • Greg-DB's avatar
      Greg-DB
      Icon for Dropbox Staff rankDropbox Staff

      tuancrab Thanks for the feedback. Dropbox doesn't offer a feature exactly like this, but I've sent this along as a feature request.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,885 PostsLatest Activity: 11 hours ago
326 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!