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?
4 Answers
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
-
1Love this idea, as long as the filename is over 8 characters. It's the first windows solution I thought of.– RobFeb 9, 2012 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!– ShevekFeb 9, 2012 at 20:00
-
I wonder if you can do the same thing with the filename quoted. i.e. ren "file|name" filename– hookenzFeb 9, 2012 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!– ShevekFeb 10, 2012 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):
Download Ubuntu and burn a Live CD.
Boot from the Live CD.
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.– RobFeb 9, 2012 at 19:20
-
1
-
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.– DennisFeb 9, 2012 at 19:36
-
1change it to
for f in "$(find . | grep '|')";
or it'll mess up with files with spaces.– RobFeb 9, 2012 at 23:46 -
1Love the idea that you have to download another operating system to fix windows.– hookenzFeb 9, 2012 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.
dir /x
will list shortnames that you can use.