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
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