Skip to content

rclone move does not delete empty folders #1642

Closed

Description

@OskarStark

for testing:

create the following structure:

  • Foo (folder)
    • file.mkv
  • other_file.mkv

after using rclone move, i ended up with the following structure:

  • Foo (folder) - empty

IMO, Foo folder should be removed!

What is your rclone version (eg output from rclone -V)
1.37

Which OS you are using and how many bits (eg Windows 7, 64 bit)
Linux and OSX

Which cloud storage system are you using? (eg Google Drive)
from local to dropbox

The command you were trying to run (eg rclone copy /tmp remote:tmp)
rclone move ~/Desktop/SYNC dropbox:dekstop/sync --transfers=4 --stats=2s -v

Activity

  1. ncw commented on Sep 1, 2017

    @ncw
    Member

    I think this is probably fixed in the latest beta can you try that?

  2. OskarStark commented on Sep 1, 2017

    @OskarStark
    Author

    Thank you for your feedback, I will try that and keep you updated 👍

  3. OskarStark commented on Sep 2, 2017

    @OskarStark
    Author

    looks like it is not fixed in the latest beta :(

  4. OskarStark commented on Sep 4, 2017

    @OskarStark
    Author

    Using this version:

    rclone v1.37-117-g58f7b4ed\ufffd\ufffd
    - os/arch: linux/amd64
    - go version: go1.9
    
  5. OskarStark commented on Sep 6, 2017

    @OskarStark
    Author

    tried to use move from amazon drive to dropbox, but doesn't work either

  6. ncw commented on Sep 7, 2017

    @ncw
    Member

    I can confirm that this is a problem, empty directories on the source aren't deleted after a move.

    $ mkdir issue-1642
    $ touch issue-1642/dir
    $ rm issue-1642/dir
    $ mkdir issue-1642/dir
    $ touch issue-1642/dir/file.txt
    $ rclone -vv move issue-1642 dropbox:issue-1642
    2017/09/07 10:11:54 DEBUG : rclone: Version "v1.37-121-gfe536f3f" starting with parameters ["rclone" "-vv" "move" "issue-1642" "dropbox:issue-1642"]
    2017/09/07 10:11:54 INFO  : Dropbox root 'issue-1642': Modify window is 1s
    2017/09/07 10:11:55 INFO  : Dropbox root 'issue-1642': Waiting for checks to finish
    2017/09/07 10:11:55 INFO  : Dropbox root 'issue-1642': Waiting for transfers to finish
    2017/09/07 10:11:56 INFO  : dir/file.txt: Copied (new)
    2017/09/07 10:11:56 INFO  : dir/file.txt: Deleted
    2017/09/07 10:11:56 INFO  : 
    Transferred:      0 Bytes (0 Bytes/s)
    Errors:                 0
    Checks:                 1
    Transferred:            1
    Elapsed time:        2.8s
    
    2017/09/07 10:11:56 DEBUG : Go routines at exit 7
    2017/09/07 10:11:56 DEBUG : rclone: Version "v1.37-121-gfe536f3f" finishing with parameters ["rclone" "-vv" "move" "issue-1642" "dropbox:issue-1642"]
    $ tree issue-1642/
    issue-1642/
    └── dir
    
    0 directories, 0 files
    
  7. added this to the v1.39 milestone on Sep 7, 2017
  8. OskarStark commented on Sep 7, 2017

    @OskarStark
    Author

    thank you for the feedback 👍

  9. winternet-studio commented on Sep 19, 2017

    @winternet-studio

    This has been an issue for a long time. Same issue with rclone copy. Why are new releases being made without such a critical thing being fixed? The program is hardly usable the way it is...

  10. winternet-studio commented on Sep 20, 2017

    @winternet-studio

    I made a script to synchronize also the folders so that it will become an exact copy, so now it is usable for me. If anybody is interested the PHP script I made is below. It is not very efficient in getting the folders deleted but it gets the job done.

    How to use it:

    • Install PHP if it is not already installed (sudo apt-get install php5 on Linux/Debian)
    • Save the above script to file (eg. dirs_cleanup.php)
    • Modify the settings in the top of the file
    • Run the script: php dirs_cleanup.php. It is safe to do this, it doesn't delete anything. It generates a bash script with rclone commands which you can check yourself before you run it afterwards.
    <?php
    // SETTINGS:
    $remote_path = 'YourRemoteName:/var-www/';
    $remote_extraflags = '';
    $local_path  = '/var/www/';
    $local_extraflags = '--exclude=cache/**';
    
    // ------------------------------------------------------------------------------------
    $temp_folder = '/tmp/';  //folder to store temporary files in
    
    echo '---- REMOTE LISTING ----------------------------------------------------------------------------------------'. PHP_EOL;
    $exitcode = null;
    passthru('rclone lsjson "'. $remote_path .'" --no-modtime --recursive '. $remote_extraflags .' | tee '. $temp_folder .'filelist_remote.json', $exitcode);
    if ($exitcode !== 0) {
    	die('Creating file list on remote failed with exit code '. $exitcode);
    }
    echo '------------------------------------------------------------------------------------------------------------'. PHP_EOL;
    
    echo '---- LOCAL LISTING -----------------------------------------------------------------------------------------'. PHP_EOL;
    $exitcode = null;
    passthru('rclone lsjson "'. $local_path  .'" --no-modtime --recursive '. $local_extraflags  .' | tee '. $temp_folder .'filelist_local.json',  $exitcode);
    if ($exitcode !== 0) {
    	die('Creating file list on remote failed with exit code '. $exitcode);
    }
    echo '------------------------------------------------------------------------------------------------------------'. PHP_EOL;
    
    $filelist_local  = file_get_contents($temp_folder .'filelist_local.json');
    $filelist_remote = file_get_contents($temp_folder .'filelist_remote.json');
    
    $filelist_local  = json_decode($filelist_local,  false);
    $filelist_remote = json_decode($filelist_remote, false);
    
    $local_folders = [];
    foreach ($filelist_local as $dir) {
    	if ($dir->IsDir) {
    		$local_folders[] = $dir->Path;
    	}
    }
    
    
    echo '---- DIRS TO DELETE ----------------------------------------------------------------------------------------'. PHP_EOL;
    $all_commands = [];
    foreach ($filelist_remote as $dir) {
    	if ($dir->IsDir) {
    		if (!in_array($dir->Path, $local_folders, true)) {
    			$fullpath = rtrim($remote_path, '/') .'/'. $dir->Path;
    			$delete_cmd = 'rclone rmdir "'. $fullpath .'" -v'. PHP_EOL;
    			$all_commands[] = $delete_cmd;
    			echo $delete_cmd;
    		}
    	}
    }
    rsort($all_commands);  //so that child folders are deleted before parent folders
    
    echo PHP_EOL;
    echo count($all_commands) .' directories to be deleted.'. PHP_EOL;
    
    if (!empty($all_commands)) {
    	file_put_contents('dirs_to_delete.sh', '#!/bin/bash'. PHP_EOL . implode('', $all_commands));
    	echo 'Run `bash dirs_to_delete.sh` to perform the deletion.'. PHP_EOL;
    } else {
    	@unlink('dirs_to_delete.sh');
    }
  11. ishuah commented on Oct 29, 2017

    @ishuah
    Collaborator

    I'm taking this up, if it's not a problem @ncw

  12. martimarkov commented on Oct 31, 2017

    @martimarkov

    @ishuah ready to test as soon as the feature is ready. :)

  13. ncw commented on Nov 1, 2017

    @ncw
    Member

    @ishuah that would be great - thanks :-)

  14. ncw commented on Nov 7, 2017

    @ncw
    Member
  15. martimarkov commented on Nov 7, 2017

    @martimarkov

    @ncw If the folders are empty and I use
    move that should mean the folders get deleted, right?

  16. ishuah commented on Nov 8, 2017

    @ishuah
    Collaborator

    Hi @martimarkov
    Yes, if you move empty directories they get deleted. Same applies for subdirectories.
    Hope this answers your question!

  17. Aidzo commented on Nov 15, 2017

    @Aidzo

    Using the beta build https://beta.rclone.org/v1.38-093-gc65734ee/ but for some reason its also deleting the source folder for example rclone move /home/example/ I want to move all the folders and files in folder example and delete them which its doing but its also delete the example folder any way to fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions