Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Renaming Hidden and System files Command

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
like image 299
Built on Sin Avatar asked Jul 30 '13 04:07

Built on Sin


People also ask

How do you rename hidden files in Linux?

To unhide a file, go to the folder containing the hidden file and click the view options button in the toolbar and pick Show Hidden Files. Then, find the hidden file and rename it so that it does not have a . in front of its name.

How do you rename a system file?

Right-click on the item and select Rename, or select the file and press F2 . Type the new name and press Enter or click Rename.

Which command is used to hidden files?

Using the command line command dir /ah displays the files with the Hidden attribute. In addition, there is a System file attribute that can be set on a file, which also causes the file to be hidden in directory listings. Use the command line command dir /as to display the files with the System attribute.


1 Answers

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
like image 65
Ansgar Wiechers Avatar answered Sep 21 '22 22:09

Ansgar Wiechers