github icon indicating copy to clipboard operation
github copied to clipboard

Option to delete extracted folder after install

Open bquistorff opened this issue 3 years ago • 2 comments

Using github to install a particular version of a package, e.g. rcall, (on Windows, Stata 15) leaves behind an rcall-X.X.X folder extracted from the zip file. It would be good to have an option to delete this after installation, especially as this folder has the dynamic element of the version (e.g. "stable" -> "3.0.7"). If I'm using github in a script, it would be hard for the script to know the version always and delete the folder programmatically. It might even be good to have this option by default.

bquistorff avatar Sep 20 '21 13:09 bquistorff

I totally agree! If "someone" kindly writes a programs that takes a directory name and removes it - for all operating systems - i gladly merge it. It is very annoying to have the unzipped directory remaining... I'm just heavily overwhelmed at the moment to develop and test such a program, no matter how simple it seems to be... please feel free to take the lead

haghish avatar Sep 20 '21 21:09 haghish

Some random code I had lying around. Would need to be test.

mata
/*
 *@brief Recursively removes folder with files it in it
 *@param path Directory path to remove
 */
real scalar function rmdir_complete(string scalar path)
{
	if (!regexm(path,"[/\]$")) path = path+"/"
	// display("{hline}{break}Entering folder "+path)
	
	string colvector dirs, files
	
	dirs  = dir(path,"dirs","*",1)
	files = dir(path,"files","*",1)
	
	real scalar i

	for(i=1;i<=length(dirs);i++){
		rmdir_complete(dirs[i])
	}
	
	for(i=1;i<=length(files);i++){
		unlink(files[i])
	}
	rmdir(path)
}
end

bquistorff avatar Sep 21 '21 13:09 bquistorff