11

I'm trying to figure out a way to rename Desktop.ini to *.ini and back again. The problem is I need to do this with the attributes in tact (So I cannot remove hidden and system and then rename). The only solution I have come up with is xcopy and del but I am having trouble with the syntax on options, source options and destination options.

This is what I have come up with:

@ECHO OFF

xcopy /H /R Desktop.ini Desktop.txt /K
del /Q /AHS Desktop.ini
xcopy /H /R Desktop.txt Desktop.ini /K
del /Q /AHS Desktop.txt

Pause

exit /b
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Built on Sin
  • 351
  • 2
  • 6
  • 19

2 Answers2

12

When using ren you must remove hidden and system flags, rename the file, then set the flags again:

attrib -s -h desktop.ini
ren desktop.ini desktop.txt
attrib +s +h desktop.txt

If you can't do that, you have to use something else, e.g. VBScript:

Set fso = CreateObject("Scripting.FileSystemObject")
fso.GetFile(WScript.Arguments(0)).Name = WScript.Arguments(1)

or PowerShell:

Rename-Item 'desktop.ini' 'desktop.txt' -Force
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • 1
    As I stated originally I need the attributes in tact, I cannot get rid of the attributes and read them without having to rename the file again. "The problem is I need to do this with the attributes in tact (So I cannot remove hidden and system and then rename)." – Built on Sin Jul 30 '13 at 14:12
  • Note to googlers: **`-s`** marks a *system* file, while **`-h`** means a normal hidden file. https://en.wikipedia.org/wiki/File_attribute#DOS_and_Windows – Marc.2377 Dec 14 '18 at 21:14
-3

For delete all Desktop.ini Files, you can use

DEL /S Desktop.ini
Hiren gardhariya
  • 1,247
  • 10
  • 29
  • That would be fine if I merely wanted to delete the files. I need to rename Desktop.ini (With attributes hidden and system) to *.* and back again (With same attributes) – Built on Sin Jul 30 '13 at 04:58