Renaming Hidden and System files Command
Asked Answered
G

2

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
Gamester answered 30/7, 2013 at 4:10 Comment(2)
If you reveal the actual task then a solution may be more obvious.Lifelong
Is there any solution to this yet? I had encountered this scenario too..Taxicab
K
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
Kalikow answered 30/7, 2013 at 6:59 Comment(2)
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)."Gamester
Note to googlers: -s marks a system file, while -h means a normal hidden file. en.wikipedia.org/wiki/File_attribute#DOS_and_WindowsVariegated
H
-3

For delete all Desktop.ini Files, you can use

DEL /S Desktop.ini
Hobbs answered 30/7, 2013 at 4:23 Comment(1)
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)Gamester

© 2022 - 2024 — McMap. All rights reserved.