Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Remove part of foldername

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
Putte_h
Posts: 2
Joined: 2018-10-16 12:19
Location: Sweden

Remove part of foldername

#1 Post by Putte_h »

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.

User avatar
bw123
Posts: 4015
Joined: 2011-05-09 06:02
Has thanked: 1 time
Been thanked: 28 times

Re: Remove part of foldername

#2 Post by bw123 »

resigned by AI ChatGPT

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

Re: Remove part of foldername

#3 Post by Putte_h »

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

reinob
Posts: 1189
Joined: 2014-06-30 11:42
Has thanked: 97 times
Been thanked: 47 times

Re: Remove part of foldername

#4 Post by reinob »

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!

Post Reply