{"id":26214847,"url":"https://github.com/charlierobin/cleaning-unity-projects-using-go","last_synced_at":"2026-04-19T20:32:33.857Z","repository":{"id":231451823,"uuid":"625989253","full_name":"charlierobin/cleaning-unity-projects-using-go","owner":"charlierobin","description":"A go version of the Python Unity project cleaner script","archived":false,"fork":false,"pushed_at":"2023-04-21T04:24:09.000Z","size":41737,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-04T03:45:26.073Z","etag":null,"topics":["golang","unity3d"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/charlierobin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-04-10T15:00:41.000Z","updated_at":"2024-04-04T03:45:28.195Z","dependencies_parsed_at":"2024-04-04T03:55:36.511Z","dependency_job_id":null,"html_url":"https://github.com/charlierobin/cleaning-unity-projects-using-go","commit_stats":null,"previous_names":["charlierobin/cleaning-unity-projects-using-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fcleaning-unity-projects-using-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fcleaning-unity-projects-using-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fcleaning-unity-projects-using-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlierobin%2Fcleaning-unity-projects-using-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlierobin","download_url":"https://codeload.github.com/charlierobin/cleaning-unity-projects-using-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196619,"owners_count":20251861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","unity3d"],"created_at":"2025-03-12T10:18:42.079Z","updated_at":"2025-12-11T22:38:48.525Z","avatar_url":"https://github.com/charlierobin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A suite of compiled Go command line apps for detecting and cleaning up Unity project directories\n \nA Go version of the Python Unity projects cleaner script ([here](https://github.com/charlierobin/clean-unity-projects)).\n\nFor a bit of additional interest, I split the app up into constituent apps, each of which carries out a particular function. (As opposed to keeping it all in one big monolithic thing, which is what the Python script is.)\n\nThe main app is [unity-projects-cleaner](https://github.com/charlierobin/cleaning-unity-projects-using-go/tree/main/unity-projects-cleaner)\n\nThis presents a list of places/mounted volumes on your computer, allows you to select one or more of them, then scans those locations, detects Unity projects folders, lists them, then gives you the option of “cleaning” them, ie: moving the `Logs`, `Library` and `obj` folders to the trash.\n\nOn my main work drive, with 85 Unity projects, most of which I hardly look at any more, this freed up **a lot** of extra free space.\n\nSo, the up side: lots of new extra free space.\n\nThe down side: if you ever come back to open any of those projects, it will take a bit longer because Unity will have to regenerate a load of cached stuff. On a big project, that can take quite a bit of time. *What the heck, for me it was worth it.*\n\nhttps://user-images.githubusercontent.com/10506323/233540403-978f67d2-2a73-4555-b9b9-2c4f0ce805e5.mp4\n\nThe **main** components are:\n\n## unity-projects-cleaner\n\napp calls the other apps via Go’s `os/exec` package:\n\n```\ncmd := exec.Command(\"shellCommandHere\", arg1, arg2, arg3)\nstdout, err := cmd.Output()\n```\n\netc.\n\nThey all return their results via `stdout`.\n\nThe way the functionality has been split up is all a bit contrived, but apart from having another look at Go, it was just something I was interested in experimenting with.\n\nThe components are:\n\n### list-mounted-volumes\n\nDoes exactly what it says: returns a list of the user’s mounted volumes.\n\nUnder the hood, it just wraps `df` and filters out most of what is returned (the macOS Recovery volume and a load of other stuff) because all I was really interested in were any mounted external volumes, not all the internal system rubbish (which on my system was \"/\", \"/dev\", \"/System/Volumes/Data\", \"/private/var/vm\", \"/System/Volumes/Data/home\", \"/Volumes/Recovery\").\n\nThe app adds the user’s home documents directory to the list of external volumes derived from above, and allows the user to selected one of more places to be scanned. (If nothing is selected, the app exits.)\n\nEach selected place is in turn passed to …\n\n### find-unity-project-folders\n\nThis uses `filepath.Walk` to look for Unity project folders.\n\nEach candidate path is passed to …\n\n### get-unity-project\n\n… which examines it to see if it’s a Unity project.\n\nA Unity project folder is defined as a folder containing `Assets`, `Packages`, `ProjectSettings` and `UserSettings` subdirectories, with a `ProjectVersion.txt` file and a `ProjectSettings.asset` file in the `ProjectSettings` folder.\n\nIf found, some data is extracted and returned: the Unity editor version of the project, the product name and the company name. (As set in the Player section of the Project Settings editor window.)\n\nOnce we have a list of project folders, they can be reviewed just to check that all seems well.\n\nIf the user then elects to go ahead with a clean, each project folder path is sent to:\n\n### clean-unity-project\n\nThis actually deletes the three cache folders (`Logs`, `Library` and `obj`), using:\n\n### trash\n\nThis also uses `exec.Command`, calling `osascript` to instruct **the Finder** to move the specified item to the user‘s trash.\n\nIt appends a note to the folder name so it can still be identified once in the trash, just in case something goes wrong.\n\nSo the Logs folder in a project called “Asteroids” will end up in the trash named “Logs (from Asteroids)”.\n\nI used this method instead of just using `rm` (or just directly deleting the file using Go’s filesystem commands) partly to see how else it could be done, but also because I wanted a last line of defence just in case of error. Doing it this way means that there’s a chance to review the deleted folders in the trash before emptying it, and also the Finder’s “Put Back” command can be used to replace any item back in its original place with ease.\n\nThe drawback of this is that the `trash` app will **possibly** need to be granted accessibility permissions, depending on what version of macOS / OSX you are using.\n\n### Finally …\n\nBecause all the deleted folders are not actually deleted but are only moved to the trash, you won’t actually get hard drive space back until you commit yourself to emptying your trash.\n\n## Building\n\nIn Terminal, cd to the project directory, then run [build.command](https://github.com/charlierobin/cleaning-unity-projects-using-go/blob/main/build.command)\n\nThis compiles all the components for both arm64 (aka Apple Silicon, the new M chips) and amd64 (ie: Intel 64 bit).\n\nThe command then runs `mv` to move the amd64 binaries up to the **top level of the build directory**, because that’s where I’ve been running them from, and that’s where they expect to be. (Hence the presence of `config.json` in this directory, which we'll get to later.) You will need to edit this if your Mac uses Apple’s new chips.\n\n## Variations on a theme\n\nIf all that seems a bit too involved, and you prefer doing more stuff by yourself, you can call `find-unity-project-folders` directly from the command line, just pass in the path where you want the find to start.\n\nThe first parameter to `find-unity-project-folders` is always the path to be checked. After that, passing in -v turns on the verbose logging option (to a log file created in the build directory). Any other paths passed in are treated as locations to skip, which helps in speeding the scan process up. (I have a large `Applications` folder on the same drive I was checking, as well as a large fonts folder, so this came in handy.)\n\nAlternatively, you can add paths to be skipped to the `config.json` file, also in the builds folders.\n\nOnce you have your list of Unity projects, you can call `clean-unity-project` on a case by case basis:\n\n`clean-unity-project /path/to/unity/project/here`\n\n`clean-unity-project` calls `get-unity-project` just to check that the path you have passed is indeed a Unity project.\n\nYou can call `get-unity-project` yourself to check whether or not the app will identify the folder as a Unity project:\n\n`get-unity-project /path/to/unity/project/here`\n\nIf it thinks it’s a Unity project, you’ll see the path, the Unity editor version, product name, and company name output.\n\nOtherwise you’ll see nothing.\n\n## Notes\n\nWith the exception of the implementation of `trash` and `list-mounted-volumes`, I think most of this would be happy enough on Windows with a bit of tweaking here and there. (See the additional added notes below.) But having said that, I’ve not actually tested any of it out.\n\n---\n\n### Additional observations on the above…\n\nThe above is perhaps not really true anymore, as I’ve added `picker`, which is a generic app for selecting from a bunch of options. It’s used both to allow the user to select from the list of available volumes, and to select from the list of found projects.\n\nIt’s opened by Applescript commands sent to the Terminal app, because I wanted it to appear in a new tab, whilst the calling app waits in the background. (There was no particular compelling design decision behind this, I was just curious to see how it could be made to work.)\n\nWhich means that to get it working on Windows or Linux you’ll have to deal with the above, as well as the couple of other places where it’s all gone a bit macOS-centric.\n\n---\n\nAt the moment, everything is designed to be run from the top level of the `build` directory. (That’s where the `config.json` and log file live, and that’s where all the apps will expect to find each other when they try to call each other. There’s no adding these apps to your bash path or anything like that.)\n\nThere are other alternatives to `trash`, like this one:\n\nhttps://github.com/ali-rantakari/trash\n\n… or …\n\nhttps://github.com/morgant/tools-osx\n\n… which could quite easily be substituted in if you preferred.\n\n`stdout` is used for everything, all errors are output to the log file.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlierobin%2Fcleaning-unity-projects-using-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlierobin%2Fcleaning-unity-projects-using-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlierobin%2Fcleaning-unity-projects-using-go/lists"}