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?

Brad Patton
  • 10,540
  • 12
  • 40
  • 68
Vineet
  • 439
  • 4
  • 13
  • does `*filename.csv` work? – BlueRaja - Danny Pflughoeft May 02 '13 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.. – BlueRaja - Danny Pflughoeft May 02 '13 at 20:39
  • outfile = open('G:\\ohlc_file.csv', 'w') This script was executed from Ubuntu. – Vineet May 03 '13 at 04:03
  • 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 03 '13 at 07:47
  • All right. I will report the bug. – Vineet May 03 '13 at 07:51
  • 6
    https://bugs.launchpad.net/ubuntu/+bug/1175933 – Vineet May 03 '13 at 08:22
  • 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 03 '13 at 11:55
  • [Perhaps you can simply run `chkdsk` and it will be deleted.](http://superuser.com/a/240950/98519) – Alvin Wong May 03 '13 at 15:45
  • Next time boot back into Ubuntu and either manually rename it or write a python script to rename it. :) – Mark Allen May 03 '13 at 22:03
  • what was the code you used to create the file? you made the file while running XP? that looks like a XP bug. I remmeber I had made something similar long back. used java to rename it - cd to that folder in prompt, called program with * and then renamed it (folder had only 1 file) – tgkprog May 04 '13 at 08:23
  • [this guy has it right](https://bugs.launchpad.net/ubuntu/+bug/1175933/comments/4): it’s not a bug, but there is a way to avoid it, which should be used if you want to avoid it; that’s the answer: remove it and mount with the `windows_names` option next time. – flying sheep May 04 '13 at 14:33

4 Answers4

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.

Sekhemty
  • 9,166
  • 18
  • 60
  • 97
  • 1
    I am dual-booting with Ubuntu. So this can be tried easily. Let me try and give feedback here. Thanks. – Vineet May 02 '13 at 12:49
  • 7
    Done. From Ubuntu, I deleted. the file. Thanks. – Vineet May 02 '13 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. – Scott Chamberlain May 05 '13 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"
Kevin Fegan
  • 4,777
  • 3
  • 24
  • 37
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

Rich Homolka
  • 31,057
  • 6
  • 55
  • 80