Remove part of foldername

If none of the more specific forums is the right place to ask

Remove part of foldername

Postby Putte_h » 2018-10-16 12:59

Dont know if this are the right place but i try.

Im looking for a script that removes part of foldername. I have alot of folders that looks like:

- My images <-- Main folder
- Sync Mobile SD 2018-12-18 (2018) - rkgavgtr
- Sync Mobile Internal 2018-12-18 (2018) - rabavgtr

Etc. (There's a couple years sync)

The thing is that the string before and after the year sometimes are at diffrent length.

Im looking for a script that I can run that removes everything after the ")" on every folder in folder "My images".

Best Regards
Patrick.
Putte_h
 
Posts: 2
Joined: 2018-10-16 12:19
Location: Sweden

Re: Remove part of foldername

Postby bw123 » 2018-10-16 14:12

User avatar
bw123
 
Posts: 3528
Joined: 2011-05-09 06:02
Location: TN_USA

Re: Remove part of foldername

Postby Putte_h » 2018-10-17 16:12

I've been going to google for a couple of weeks but have not found what I'm looking for. I'm not so familiar with this with bash or script generally in debian.

Best Regards
Patrick
Best Regards
Patrick
Putte_h
 
Posts: 2
Joined: 2018-10-16 12:19
Location: Sweden

Re: Remove part of foldername

Postby reinob » 2018-10-17 18:01

Putte_h wrote:Dont know if this are the right place but i try.

Im looking for a script that removes part of foldername. I have alot of folders that looks like:

- My images <-- Main folder
- Sync Mobile SD 2018-12-18 (2018) - rkgavgtr
- Sync Mobile Internal 2018-12-18 (2018) - rabavgtr

Etc. (There's a couple years sync)

The thing is that the string before and after the year sometimes are at diffrent length.

Im looking for a script that I can run that removes everything after the ")" on every folder in folder "My images".

Best Regards
Patrick.


Something like this should work (make sure you have "apt install rename").

$ find -type f -name \*\(\*\)\* -exec rename -v 's/\)(.+)$/\)/' {} \;

this will look for files (-type f) matching "*(*)*" (i.e. having something in brackets), and rename it replacing from the right bracket until the end, with a right bracket.

You can remove the "-v" to have it run silently. You can also add "-n" (i.e. .. rename -n -v ..) to only show what rename would do, without actually doing it.

I take no responsibility if you wipe your p0rn!
reinob
 
Posts: 560
Joined: 2014-06-30 11:42


Return to General Questions

Who is online

Users browsing this forum: tynman and 11 guests

fashionable