Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I often paste titles of PDFs into their filenames so I can easily search for them. They often have invalid characters like newlines or :, and Windows pops up a stupid error and then reverts the filename to its original:

enter image description here

I don't care about those characters and would be perfectly happy if it replaced them with - or removed them entirely. Is there some way I can do this? Any system setting for disabling this prompt?

The best I can think of is an AutoHotkey script with its own keyboard shortcut for "paste clipboard but remove invalid characters first", which is what I'm currently using.

share|improve this question
1  
If you're doing this regularly, perhaps a better automated process would work more efficiently. –  Hello71 Oct 29 '11 at 23:03
    
@Hello71: What does that mean? –  endolith Oct 30 '11 at 17:38
add comment

3 Answers

I had a similar issue with my music files. I ended up writing a Java program to rename everything. I was lucky since there were some free mp3 ID3 metadata libraries available. I'm not sure if there is a free library available to read PDF metadata. There is a discussion about it here.

After a lot of searching, I found this tool (A-PDF Rename) which claims to be able to rename PDF files based on metadata. I have never seen or heard of it before. Purchase and download at your own risk.

share|improve this answer
add comment

You could try an AutoIT script that would replace the invalid characters in your clipboard.

I don't use AutoIT myself, so I don't know the scripting language, but many people seem to be manipulating the clipboard contents using ClipGet() & ClipPut(value). I didn't see a good way to "monitor" the clipboard, mainly I saw loops that slept for 1 second between running.

I think this is what @Hello71 mean. Hope this point you in the right direction.

share|improve this answer
add comment

I've been using this AutoHotkey keyboard shortcut, which works ok, but isn't "automatic":

;------------------------------------------------------------------------------
; Win+V: Paste as plain text from clipboard
;------------------------------------------------------------------------------
#v::
   Clip0 = %ClipBoardAll%
   ClipBoard = %ClipBoard% ; Convert to plain text
   Send ^v ; For best compatibility: SendPlay
   Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
   ClipBoard = %Clip0% ; Restore original ClipBoard
   VarSetCapacity(Clip0, 0) ; Free memory
Return

;------------------------------------------------------------------------------
; Win+Alt+V: Paste plain text only, stripping characters unsafe for filenames
;------------------------------------------------------------------------------
#!v:: ; paste without formatting
  StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
  clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
  StringLeft, 1st, clipboardt, 1
  IfInString, 1st, %A_Space%
    StringTrimLeft, clipboardt, clipboardt, 1
  StringRIght, last, clipboardt, 1
  IfInString, last, %A_Space%
    StringTrimRight, clipboardt, clipboardt, 1
;Send {Raw}%clipboardt%

  Clip0 = %ClipBoardAll%
  ClipBoard = %clipboardt% ; Convert to plain text
  Send ^v ; For best compatibility: SendPlay
  Sleep 50 ; Don't change clipboard while it is pasted! (Sleep > 0)
  ClipBoard = %Clip0% ; Restore original ClipBoard
  VarSetCapacity(Clip0, 0) ; Free memory
  clipboardt =
return
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.