30

Inadvertently, I have created a file named g:\filename.csv on Windows XP through a Python script.

Note that g:\filename.csv is the filename. Actually it is saved on the F: drive.

I can't rename it using command prompt (ren oldfilename newfilename) or using F2 in an Explorer window. It says "can't read from drive" - Windows thinks the file is on the G: drive.

Is there any way to rename it?

11
  • does *filename.csv work? May 2, 2013 at 20:35
  • 8
    Also, though you have your solution already, could you post the code that created the file? I didn't think the Windows File APIs even allowed you to specify an invalid filename.. May 2, 2013 at 20:39
  • 5
    You should file a bug to Linux/Ubuntu. The filesystem driver should know that this is an invalid filename for the targeted drive and consequently shouldn't allow to create such a file. It should still allow to address such files if they already exist, in order to remove or rename them though.
    – Devolus
    May 3, 2013 at 7:47
  • 6
  • 2
    There's actually nothing invalid about this file name as far as NTFS is concerned, it's merely a limitation of Windows that prevents it from being properly referenced.
    – phogg
    May 3, 2013 at 11:55

4 Answers 4

21

This couldn't be the fastest solution, but it should work.
If you boot a Live Linux distro you can delete it, since Linux uses a different method to identify partitions and won't be forced to think that your file is a drive. I suggest you Parted Magic, that has many handy tools for disk and system maintenance and, beside your current concern, is always useful to have it at hand.

3
  • 1
    I am dual-booting with Ubuntu. So this can be tried easily. Let me try and give feedback here. Thanks.
    – Vineet
    May 2, 2013 at 12:49
  • 7
    Done. From Ubuntu, I deleted. the file. Thanks.
    – Vineet
    May 2, 2013 at 12:53
  • 1
    I used to have the top rated answer that said use \\?\ before the name. I was wrong and that method will not work, so I deleted my answer. You need to use this answer's method or one of the other answers. May 5, 2013 at 19:37
7

If your OS Windows then you can use the following trick:

1. Issue command `dir /X`
2. Find out your file in 8 dot 3 notation
3. Use 8 dot 3 notation for file operations as ren, del, copy, print and others.

Note, if you managed to create file with name con or some other Windows device reserved names then you are out of luck with the approach.

6

You could also try...

From a Windows Command Prompt:

ren "F:???filename.csv" "filename.csv"

or

ren "F:*.csv" "filename.csv"
4

You could always try Cygwin. The path name filter in it should be more compliant to this type of error, since this doesn't violate POSIX standards. Install bash and fileutils and then try rm /cygdrive/f/g:\\filename.csv

Not the answer you're looking for? Browse other questions tagged .