In Windows 7 I can't copy the file with | in the name. Gives me an error Can not find the file. I have around 30GB of files and all contains that character. Any idea how can I copy them to another NTFS partition?

  • How did you create those files in the first place? – Dennis Feb 9 '12 at 13:42
  • Downloaded from torrents. – Pablo Feb 9 '12 at 13:42
  • Do you still have the torrent? If you do, use the torrent client and move the storage, since it obviously can handle these improper file names. – Dennis Feb 9 '12 at 13:45
  • Nop, unfortunately I don't have such torrent registered anymore, neither I have Linux to move those files(I remember I moved them from Ubuntu to Windows 7 partition). – Pablo Feb 9 '12 at 13:52
  • 1
    mounting the drives with a linux liveCD/USB would be a quick and clean solution, but I wonder if there's a way to do it from just windows? I just tried making a file with | in it from my linux machine on my windows machine and it yelled at me. Downloading from a running https server on my netbook didn't work either, it changed the | to a -. Maybe try moving them with the command prompt and shortnames? dir /x will list shortnames that you can use. – Rob Feb 9 '12 at 13:53

Command Line is your friend.

Open a CMD and CD to the location of the files.

Enter dir /X and this will show you the old DOS 8.3 names with ~1, ~2 etc alongside the long filename.

You can then copy/rename using the 8.3 names

You can mix 8.3 and long filenames when renaming:

ren THISIS~1.TXT "this is renamed.txt" will work

enter image description here

  • 1
    Love this idea, as long as the filename is over 8 characters. It's the first windows solution I thought of. – Rob Feb 9 '12 at 19:36
  • 2
    @Rob even if the filename is less than 8 chars I believe it will give an alternative to use in this case where there are illegal chars, It's a bit difficult to test tho! – Shevek Feb 9 '12 at 20:00
  • I wonder if you can do the same thing with the filename quoted. i.e. ren "file|name" filename – Matt H Feb 9 '12 at 23:57
  • 1
    @MattH I don't think so as it is still an illegal character for a Windows filename. Again, very hard to test as it is difficult to create files with that character in the filename! – Shevek Feb 10 '12 at 9:44

The \\?\ prefix tells Windows that your path is perfectly fine and that you don't want anything done to it. That does mean it's less forgiving. E.g. dir "\\?\C:" doesn't work. The proper path is dir "\\?\C:\".

This should help you bypass the restriction on using | in NTFS filenames. However, you should still quote the filename so that CMD.EXE doesn't interpret the |.


Invalid characters in file name will cause problems rather sooner than later. I'd recommend you rename all the files to avoid further issue.

This should work (but it's untested):

  1. Download Ubuntu and burn a Live CD.

  2. Boot from the Live CD.

  3. Open a terminal, go to the folder containing the odd files and exexcute

    find . | grep "|" | awk '{ OLD=$0; gsub(/\|/, "_"); print "mv \"" OLD "\" \"" $0 "\"" }' | sh

That should replace all |s with _s.

  • I know there's an easier way to do it than with awk, but that should work. Let me ssh into my linux machine and see if it's still in my bash history. – Rob Feb 9 '12 at 19:20
  • 1
    for f in *; do mv "$f" "$(echo $f | tr '|' '_')" ; done – Rob Feb 9 '12 at 19:30
  • 1
    @Rob: That is easier. I've changed it a little so it works with subdirectories and doesn't print error message when source and destination are identical. – Dennis Feb 9 '12 at 19:36
  • 1
    change it to for f in "$(find . | grep '|')"; or it'll mess up with files with spaces. – Rob Feb 9 '12 at 23:46
  • 1
    Love the idea that you have to download another operating system to fix windows. – Matt H Feb 9 '12 at 23:56

I was going to suggest the same thing as Dennis. There are many apps available for windows as well, but I don't know how well they would do renaming files with an "invalid" character.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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