JDownloader Community - Appwork GmbH
 

Reply
 
Thread Tools Display Modes
  #1  
Old 26.12.2016, 00:44
Qulox Qulox is offline
Modem User
 
Join Date: Dec 2016
Posts: 2
Question [Help] Using Rename option to truncate long filenames with Regex

I've tried to download files with filenames longer than 255 characters, which gives a "Invalid download directory" error, so I've been trying to use the rename option on the download/linkgrabber list using regular expressions to no avail. I just want to keep the first 40 characters and the file extension, but after hours of trying I can't come up with a regex that does that.

This is what I need:
  • Search for: (THE-ENTIRE-FILANAME-IF-LONGER-THAN-40-CHARACTERS)
  • Replace by: (keep the first 40 characters and the file extension)

Could someone help me, please? I've searched everywhere but nothing I found has worked for me.


EDIT:

I've tried using:

Code:
Search for: (.*)
Replace by:  ^(.{40}).*(\..{3,4})$
But that gives me "Ilegal group reference: group index is missing" error wich according to regex101.com should be correct: **External links are only visible to Support Staff****External links are only visible to Support Staff**

Spoiler:
Code:
java.lang.IllegalArgumentException: Illegal group reference: group index is missing
	at java.util.regex.Matcher.appendReplacement(Unknown Source)
	at java.util.regex.Matcher.replaceAll(Unknown Source)
	at org.jdownloader.gui.views.components.packagetable.context.rename.RenameDialog$1.actionPerformed(RenameDialog.java:72)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.WaitDispatchSupport$2.run(Unknown Source)
	at java.awt.WaitDispatchSupport$4.run(Unknown Source)
	at java.awt.WaitDispatchSupport$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.awt.WaitDispatchSupport.enter(Unknown Source)
	at java.awt.Dialog.show(Unknown Source)
	at java.awt.Component.show(Unknown Source)
	at java.awt.Component.setVisible(Unknown Source)
	at java.awt.Window.setVisible(Unknown Source)
	at java.awt.Dialog.setVisible(Unknown Source)
	at org.appwork.utils.swing.dialog.InternDialog.setVisible(InternDialog.java:59)
	at org.appwork.utils.swing.windowmanager.WindowsWindowManager.setVisibleInternal(WindowsWindowManager.java:668)
	at org.appwork.utils.swing.windowmanager.WindowsWindowManager.setVisible(WindowsWindowManager.java:365)
	at org.appwork.utils.swing.dialog.AbstractDialog$14.runInEDT(AbstractDialog.java:1614)
	at org.appwork.utils.swing.EDTRunner.edtRun(EDTRunner.java:51)
	at org.appwork.utils.swing.EDTHelper.run(EDTHelper.java:119)
	at org.appwork.utils.swing.EDTHelper.start(EDTHelper.java:154)
	at org.appwork.utils.swing.EDTHelper.start(EDTHelper.java:139)
	at org.appwork.utils.swing.EDTRunner.<init>(EDTRunner.java:46)
	at org.appwork.utils.swing.dialog.AbstractDialog$14.<init>(AbstractDialog.java:1610)
	at org.appwork.utils.swing.dialog.AbstractDialog.setVisible(AbstractDialog.java:1610)
	at org.appwork.utils.swing.dialog.AbstractDialog._init(AbstractDialog.java:553)
	at org.appwork.utils.swing.dialog.AbstractDialog.displayDialog(AbstractDialog.java:693)
	at org.appwork.utils.swing.dialog.Dialog.showDialogRawInEDT(Dialog.java:518)
	at org.appwork.utils.swing.dialog.Dialog.showDialogRaw(Dialog.java:507)
	at org.appwork.utils.swing.dialog.Dialog$1.showDialog(Dialog.java:243)
	at jd.gui.swing.jdgui.JDGui$18.showDialog(JDGui.java:934)
	at org.appwork.utils.swing.dialog.Dialog.showDialog(Dialog.java:492)
	at org.jdownloader.gui.views.components.packagetable.context.RenameAction.actionPerformed(RenameAction.java:77)
	at javax.swing.SwingUtilities.notifyAction(Unknown Source)
	at org.jdownloader.gui.views.linkgrabber.LinkGrabberTable.processKeyBinding(LinkGrabberTable.java:408)
	at javax.swing.JComponent.processKeyBindings(Unknown Source)
	at javax.swing.JComponent.processKeyEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Last edited by Qulox; 26.12.2016 at 04:26.
Reply With Quote
  #2  
Old 26.12.2016, 06:23
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 915
Default

Code:
Search for: ^(.{40}).*(\..{3,4})$
Replace by: $1$2
Reply With Quote
  #3  
Old 26.12.2016, 12:27
Qulox Qulox is offline
Modem User
 
Join Date: Dec 2016
Posts: 2
Default

Thank you, now I'm sure why I failed those logic classes at college.

At least I learned a lot about regex. Before it just seemed like gibberish.
Reply With Quote
  #4  
Old 04.01.2017, 17:36
Jiaz's Avatar
Jiaz Jiaz is offline
JD Manager
 
Join Date: Mar 2009
Location: Germany
Posts: 67,320
Default

Thanks for the feedback and yes, regex can be pain in the xxx
__________________
JD-Dev & Server-Admin
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 13:48.
Provided By AppWork GmbH | Privacy | Imprint
Parts of the Design are used from Kirsch designed by Andrew & Austin
Powered by vBulletin® Version 3.8.10 Beta 1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.