Move selected files and folders into parent folder.
Posted: 14 Jul 2010 07:39
When you unzip a file, you usually don't know if the zipped content is in the root of the zip file or inside a single root folder of the zip file, unless you open it and look at the content.
If you have the habit of using "Extract to zipfilename\", in order to avoid tons of files cluttering your desktop if you use "Extract Here" and when the content of the file was not contained in a single root folder, you'll occasionally end up extracting the files into zipfilename\ziprootfolder\*.* where ziprootfolder is then the only item inside the zipfilename folder.
The following script helps you to move all those items into the parent folder.
The above code works fine. I wanted to let the script check the original folder, and if it is empty, then offer to delete the folder, but for some reason the moveto appears to be an asychronous command, so this doesn't work:
If you have the habit of using "Extract to zipfilename\", in order to avoid tons of files cluttering your desktop if you use "Extract Here" and when the content of the file was not contained in a single root folder, you'll occasionally end up extracting the files into zipfilename\ziprootfolder\*.* where ziprootfolder is then the only item inside the zipfilename folder.
The following script helps you to move all those items into the parent folder.
Code: Select all
$initial = getinfo("CountSelected");
if ($initial == 0) {
echo "Command aborted, nothing is selected!";
end 1;
};
$parent = RegExReplace(<curpath>, "(.*)\\[^\\]+", "$1");
$child = <curfolder>;
moveto $parent;
goto $parent;
sel "[$child]";
Code: Select all
$initial = getinfo("CountSelected");
if ($initial == 0) {
echo "Command aborted, nothing is selected!";
end 1;
};
$parent = RegExReplace(<curpath>, "(.*)\\[^\\]+", "$1");
$child = <curfolder>;
moveto $parent;
sel "a";
$remainder = getinfo("CountSelected");
goto $parent;
if ($remainder == 0) {
if (confirm("Delete the empty folder named '$child'?") == 1) {
delete $child, 1, 0;
end 1;
}
}
sel "[$child]";