Filename "Clean Up"
Filename "Clean Up"
I miss a feature, so I would like to propose:
Some downloaded files use some schemes like replacing space with dots or underscopes like:
Altap Salamander 2.53
becomes
Altap.Salamander.2.53 or Altap_Salamander_2.53
so idea is Clean Up function maybe in "Change case" command or in "Convert" command. I know about great Batch rename, but I was thinking about something quicker, more obvious
Thanks
			
			
									
						
										
						Some downloaded files use some schemes like replacing space with dots or underscopes like:
Altap Salamander 2.53
becomes
Altap.Salamander.2.53 or Altap_Salamander_2.53
so idea is Clean Up function maybe in "Change case" command or in "Convert" command. I know about great Batch rename, but I was thinking about something quicker, more obvious
Thanks
Re: Filename "Clean Up"
Batch Rename is indeed the right candidate for this kind of task, maybe a script would fit this better. But even if you created an Automation script for this purpose, the discoverability would be the same. The "quickness" of use not bad though, since you can have buttons for plugin actions.otrov wrote:I know about great Batch rename, but I was thinking about something quicker, more obvious
I don't think either of these commands cover this function, as this is neither case-changing nor character page converting.otrov wrote:so idea is Clean Up function maybe in "Change case" command or in "Convert" command
The main problem is that the clean-up cannot be accurate and definitive - the "de-spacing" process is a lossy one: If you wanted to replace spaces with underscores, you'd have a no-brainer. The reverse process is not that straight-forward, since the original filename can contain the character that is used to replace spaces, you can't be sure if this underscore/dot/dash is really a replaced space or it had been there all the time. What I'm trying to say is that this process can be automated only to some extent and maybe it's just not worth including in basic Salamander's function.
On the other hand, if there were more people with the same request, the proposal could get enough attention and support to be implemented. In the meantime, I can help you create some regular expressions to cover the common cases using Batch Rename, if you want.
Ελληνικά rulez.
			
						Re: Filename "Clean Up"
Thanks for your offer, I can handle regex pattern too, but what I have in mind, or what got me to this idea posting about "clean up", is feature that I noticed in foobar2000 audio player which is called Clean Up and does the job simply and quick (underscopes, redundant spaces...). I guess majority of AS users have contact with such files on a daily bases, thou maybe don't need to rename them but such function seems reasonable to me.
Automation script is overkill IMHO
			
			
									
						
										
						Automation script is overkill IMHO
Re: Filename "Clean Up"
From my point of view, implementing the feature in Salamander's core is overkill. Automation scripts can be created and modified by power users without the need of the developers' co-operation.otrov wrote:Automation script is overkill IMHO
Ελληνικά rulez.
			
						Re: Filename "Clean Up"
ok, maybe it's just me
thanks for conversation
			
			
									
						
										
						thanks for conversation
Re: Filename "Clean Up"
Could you post an automation script for this (or any other) renaming functionality? TIAEther wrote:But even if you created an Automation script for this purpose, [...]
Kind regards, KNUT
_____________________________________________
Satisfied Servant Salamander User from Version 1.5 till now
			
						_____________________________________________
Satisfied Servant Salamander User from Version 1.5 till now
Re: Filename "Clean Up"
For any "cleaning file names" job I use "Lupasrename" with INI-Files in the User Menu:
			
							- Command. c:\Tools\LupasRename.exe
Arguments: PATH="$(FullPath)" FILTER="$(Name)" LRFILE="c:\tools\LR_[1]ToNull.ini" RECURSIVE=0 UNDOFILE="c:\tools\LR_[1]ToNull.bat"UNDOFILE="c:\tools\LR_[1]ToNull.bat" RENAME=1 PAUSE=0
initial Directory: $(FullPath) 
- Attachments
 - 
			
		
		
				
- LR_[1]ToNull.ini.txt
 - (865 Bytes) Downloaded 751 times
 
 
Kind regards, KNUT
_____________________________________________
Satisfied Servant Salamander User from Version 1.5 till now
			
						_____________________________________________
Satisfied Servant Salamander User from Version 1.5 till now
Re: Filename "Clean Up"
Here's a clean up script as an example.
The function "CleanUp" contains the hard coded logic for replacing unwanted characters, in this case "_" and "." are replaced with a space, also multiple spaces are condensed into a single space.
			
			
									
						
										
						The function "CleanUp" contains the hard coded logic for replacing unwanted characters, in this case "_" and "." are replaced with a space, also multiple spaces are condensed into a single space.
Code: Select all
    ' clean up.vbs
    ' replace unwanted characters in file names
    ' 16.06.2010 th.
    '
    Dim Items, Fso, Item, OverwriteAnswer, Overwrite
    Set Fso = CreateObject("Scripting.FileSystemObject")
    OverwriteAnswer = 0
    '--- Identify the item(s) to rename
    If Salamander.SourcePanel.SelectedItems.Count = 0 Then
		If Salamander.SourcePanel.FocusedItem.Name <> ".." then
			CleanUpItem Salamander.SourcePanel.FocusedItem, False
		Else
			Salamander.MsgBox "Please select or focus an item first.",0,"Clean up"
			Salamander.AbortScript()
		End If
    Else
		Set Items = Salamander.SourcePanel.SelectedItems
    End If
    If VarType(Items) <> 0 Then ' vbEmpty
		'--- Set up progress dialog
		Salamander.ProgressDialog.Style = 1
		Salamander.ProgressDialog.Maximum = Items.Count
		Salamander.ProgressDialog.Show
		Salamander.ProgressDialog.AddText "Cleaning up file names ..."
		' Iterate through the item collection rename each item
		For Each Item In Items
			CleanUpItem Item, True
			If Salamander.ProgressDialog.IsCancelled then Salamander.AbortScript() ' Canceled
		Next
    End If
	Salamander.SourcePanel.DeselectAll
	
    Sub CleanUpItem(Item, ShowProgress)
		IsDirectory = (Item.Attributes And 16) <> 0
		OldFilename = Salamander.GetFullPath(Item.Name, Salamander.SourcePanel)
		If IsDirectory Then
			OldName = OldFilename
			OldExtension = ""
		Else
			SplitFilenameAndExtension Item.Name, OldName, OldExtension
		End If
		 ' Build the new name for the item
		NewFilename = Salamander.GetFullPath(CleanUp(OldName) & NewSuffix, Salamander.SourcePanel)
		If OldExtension <> "" Then NewFilename = NewFilename & "." & OldExtension
		If ShowProgress Then
			Salamander.ProgressDialog.Step(1)
			If OldFilename = NewFilename Then Exit Sub
			Salamander.ProgressDialog.AddText vbCrLf & OldFilename & " --> " & NewFilename
		End If
		Overwrite = True
		If Fso.FileExists(NewFilename) Then
			'neither "skip all" nor "all" has been pressed before, ask
			If OverwriteAnswer < 17 then _
			   OverwriteAnswer = Salamander.OverwriteDialog(Fso.GetFile(NewFilename), Fso.GetFile(OldFilename), 4)
			Select Case OverwriteAnswer
				Case 2
					Salamander.AbortScript() ' Cancel
				Case 7, 16, 17
					Overwrite = False
				Case Else ' Overwrite, target has to be deleted
					If IsDirectory then
						Fso.DeleteFolder NewFilename
					Else
						Fso.DeleteFile NewFilename
					End If
			End Select
		End If
		If Overwrite then
			If IsDirectory Then
			   Fso.MoveFolder OldFilename, NewFilename
			Else
			   Fso.MoveFile OldFilename, NewFilename
			End If
		End If
    End Sub
	Function CleanUp(FileName)
		Dim f
		f = Replace(FileName, "_", " ")
		f = Replace(f, ".", " ")
		While InStr(f, "  ") > 0
			f = Replace(f, "  ", " ")
		Wend
		CleanUp = f
	End Function
	
    Sub SplitFilenameAndExtension(FileName, Name, Extension)
          Dim n
          
          For n = Len(FileName) to 1 step -1
                If Mid(FileName, n, 1) = "." Then Exit For
          Next
          if n < 1 then
             Name = FileName
             Extension = ""
          Else
             Name = Left(FileName, n - 1)
             Extension = Mid(FileName, n + 1)
          End If
    End Sub
- 
				Jan Rysavy
 - ALTAP Staff

 - Posts: 5231
 - Joined: 08 Dec 2005, 06:34
 - Location: Novy Bor, Czech Republic
 - Contact:
 
Re: Filename "Clean Up"
What about some dedicated thread with links to all Automation scripts?
			
			
									
						
										
						Re: Filename "Clean Up"
VBS looks good and can be extended and works good, thou instead that like code lines I'll contribute with regex:

like any regex it can be done in different ways, and on first try on set of example files I scrambled this:

[edit] well, last pipe can be more accurate with this pattern: ([a-z][a-z])([A-Z]) as it matches for at least two lower case characters then upper
repeat "{2,}?" doesn't seem to be implemented
			
			
									
						
										
						
like any regex it can be done in different ways, and on first try on set of example files I scrambled this:
_|[ ]+|(\D)\.|\.(\D)|(\D)-(\D)|([a-z])([A-Z])
$(1)$(3)$(5) $(2)$(4)$(6)
_ : self explanatory [ ]+ : sqare brackets aren't necessary, but to be more readable it replaces redundant spaces with single space (\D)\.|\.(\D) : replace "." (dot) only if not surrounded by numbers (\D)-(\D)] : hyphen when surrounded by non-numerical word chars (suite yourself, it doesn't touch hyphen between spaces, i.e. "Altap - Salamander") ([a-z])([A-Z]) : insert space in joined capitalized words (i.e. "AltapSalamander" becomes "Altap Salamander", can be problematic with some "SCEnE" releases with their case games)
[edit] well, last pipe can be more accurate with this pattern: ([a-z][a-z])([A-Z]) as it matches for at least two lower case characters then upper
repeat "{2,}?" doesn't seem to be implemented
Re: Filename "Clean Up"
Why not?Jan Rysavy wrote:What about some dedicated thread with links to all Automation scripts?
Re: Filename "Clean Up"
Yep!th. wrote:Why not?Jan Rysavy wrote:What about some dedicated thread with links to all Automation scripts?It could be named "The Altap Salamander Script Store", or shorter "ASS Store".
Kind regards, KNUT
_____________________________________________
Satisfied Servant Salamander User from Version 1.5 till now
			
						_____________________________________________
Satisfied Servant Salamander User from Version 1.5 till now