Jump to content

help with shell script


Recommended Posts

My little MacOS mod "manager" sits in the game folder and tries to find all mods; the default method for this is to look for any file with a .tp2 extension.  Right now, the app sits in your game folder and drills into all subfolders to find any files that end in ".tp2", because that's how I managed to use the "find" command.

But, it finds a lot of garbage - several mods actually include internal .tp2 files that are not themselves mods, instead of giving those files a ".tpa" or ".tph" extension like a civilized person. ;)

I would really like to limit the command to finding .tp2 files in the main game folder (some old mods keep them separate from the mod folder) or one level deeper, i.e. in the mod folders themselves, but not in any mod's subfolders. 

The command currently looks like this:

find [game_folder_path] -iname *.tp2

I have no idea whether the find command can be fashioned in such a way without an unpleasant amount of complication.  Does anyone here have any idea?

Link to comment

The find option "-maxdepth 2" can be used to limit search to the game directory and the first level of subfolders in the search path. However, that might still list bogus files if there are multiple .tp2 files present in a mod folder.

find game_folder -maxdepth 2 -iname *.tp2


Alternatively you could use regular expressions for the search. However, they are really messy since you'd have to escape so many special characters:

find game_folder -regextype sed -iregex "game_folder/\(\(.\+\)/\)\?\(setup-\)\?\2\.tp2"

 

Edited by argent77
Link to comment
11 minutes ago, argent77 said:

The find option "-maxdepth 2" can be used to limit search to the game directory and the first level of subfolders in the search path. However, that might still list bogus files if there are multiple .tp2 files present in a mod folder.

It woulds get me 90% of the way there (apparently 99%, actually), which in this case is sufficient. 

EDIT - in a folder with >100 mods, I'm down to a single false positive. Thanks!!

Edited by subtledoctor
Link to comment

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...