How To Use The CMD Prompt To Change A File or Directory Attributes

DIY-Computer-Repair can help!

A while back I wrote an article about file Attributes and using the CMD Prompt or DOS Box to change the properties or attributes of a file.

Seems there is a nasty virus out on the web that likes to hide directories (Folders) and files from the user/owner.

Note: File attributes control how a file is viewed or changed therefore consider this before you change an attribute. Removing the system, read only, or hidden attribute from system files gives an opening for someone or a virus to change or delete these files.

Use this information with caution, insure you are in the correct place before executing the commands!

So you tried to remove the hidden attribute on some files and folders with Explorer but it isn't working. You need two things:

  • Administrator Rights
  • Ownership of the files/folders

First you need to check the security of the drive volume in question, with the properties window open on the drive you need to find out who owns the files on the volume, go to the Security tab.

Then highlight Administrators (computername\Administrators), then go down to the "Advanced" button and click it.

On the Owner tab you should see Administrators and your user ID if you do not see your user ID then you DO NOT have Administrative rights on the computer! You need to either log on with the Administrator's ID or add your user ID to the Administrators Group.

If you are not sure that you "Own" the files then close the drive properties and open Explorer, go to the Folder in question and check the properties, Go to the Owner tab and look at the "Owner" if your user ID is there, highlight your user ID the check the box "Replace own on sub containers and objects" this will give you ownership of the Folder and all sub folders and files under that folder.

From there you should be able to use Explorer to change the hidden attribute from the folder, sub folders, and files.

If not read on ~

One of the ways to gain control over a file or directory (this is an old DOS term where as Folders is a Windows 95 and up term) is to use the Command Prompt and go to the directory with the effected files.

Ah but, you say "How do I get there?"

Here is a tip: If you need to know a certain command for working in the DOS environment then press F1 and in search box type in "Command-line reference".

Now you have a list of all the commands you can use in the Command Prompt window or with a DOS boot disk, however with a DOS boot disk unless you have a utility that will mount an NTFS volume you will not be able to do anything to a Windows volume, DOS can not see the NTFS formatted volume.

Either use the Start button menu and navigate to the accessories and open a Command Prompt window or use the Run... from the Start button menu and type in cmd, a new window will open at the Command Prompt.

Next you need to navigate to the actual directory, lets say the path to the affected files is D:\Backup Files\June 2010 now you have a small problem because some DOS commands do not see spaces in a directory name, and when you get to the files you are going to have another problem: DOS can only see eight characters and a three character file type extension.

There are ways around these small problems. When you are using some commands/utility programs in the CMD Prompt you can not use spaces and long file names with some commands such as attrib unless you enter your text with in parentheses such as you want to go to the backup files directory you would use this: "backup files" with the command.

Before you go to the backup files directory if it is hidden you need to remove that attribute by using the attrib -h command (don't worry I will make a completer list of how to get to the drive letter, the directory, and the files shortly).

When the CMD Prompt window opens it will be on your Operating System drive and in your home or My Documents directory unless you have changed it by changing the properties of the CMD Prompt itself (I have mine set for C:\ ) so you need to get to the D: drive then to the backup files root directory for the June 2010. That is where you need to start removing the -h (hidden) attribute from the files and directories.

Your command prompt may look like this:  C:\>   The drive letter may be different or the path between the \ and the > maybe longer, it may have your home directory in it of it may even be a shared drive on a local server. I am leaving off the prompt to make each command easier to understand.

Next you go to your CMD Prompt and use the DOS syntax (type in the command - commands are all bold - explanations are not) as follows:

Change the cmd prompt to the drive volume you want to work with (if it is the C: drive then skip this step)

  • D:

Next look for your directory:

  • dir /a:h

You should see a list of hidden directories at the root of the D: drive or volume, find yours:

  • 01/05/2010  09:20 AM     <DIR>                   Backup Files

Remove the hidden file attribute from the directory 'Backup Files':

  • attrib -h "backup files" (you have to use the parentheses because of the space in the directory name for DOS commands)

Check to see if the attribute change worked:

  • attrib "backup files" (there should not be any attributes on the directory however some programs make the root directory read only, leave that as is).

Change to the root directory you need to work with:

  • cd D:\backup files (at the CMD Prompt you do not all ways have to use the parentheses)

Check the directory for hidden files:

  • dir /a:h

Here is your file:

  • 01/05/2010  10:17 AM   469,286 your hidden file you are looking for

Now you can change the attributes on all the files (*.* is a wildcard expression that will include all files and extensions) in the 'backup files' directory:

  • attrib -h *.*

Then use the dir command to list all the files by name and extension, however directories (or folders) will be listed with the this:

  • dir

 The name of the directory lists like this:

  • 01/05/2010  09:20 AM     <DIR>   Backup Files (Your hidden directory )

Files will be listed like this:

  • 01/05/2010  10:17 AM   469,286 your hidden file you are looking for

To check if the command worked pick one of the files, to see the files in the directory use:

  • attrib "your hidden file you are looking for"

The command will list the attributes like this:

  •                D:\Backup Files\June 2010\your hidden file you are looking for

If it didn't change it will look like this:

  •        H    D:\Backup Files\June 2010\your hidden file you are looking for

Suppose that a program has made the directory  and the file not read only? What would the folder attribute look like?

  •        R    D:\Backup Files\June 2010\

What would the complete path look like?

  •              D:\Backup Files\June 2010\your hidden file you are looking for

Once you have removed the hidden attribute from the files and folder then using Explorer check your work by doing a properties on the folder then some of the files in the folder.

But you say "There are folders inside the D:\Backup Files\June 2010\ folder!"

Then you would have to run the attrib command on each directory then inside each directory, yes it is a lot of work but if Explorer can't do the job and you don't have the old NT File Manager then you will have to do it the hard way, one folder at a time.

A list of commands that I used in this example:

  • D: - change to D volume or drive
  • dir - list all directories and files
  • cd - change directory
  • attrib - attribute command
  • attrib /a:h  (the switch a:h tells the attribute command to display only hidden files or directories)
  • attrib -h - remove the hidden attribute on a file or directory

What if you copied some files from a CD or DVD? Did you know that the files on a CD or DVD have the Read Only attribute? When you copy the files the attribute follows and all files copied will be read only. Normally that will be ok but if you need to change a file or a file is a template that you want to use you will not be able to save your work until you remove the read only attribute or use a different name for the file.

You can use Explorer to remove the read only but if Explorer can't remover the attribute then use the steps above and replace the letter h with the letter r.

Last thing:

Do NOT use the attrib command on the Root of the Operating System drive (normally C: ) because removing the system, read only, and hidden attributes of the system files invites disaster, a virus may not have the commands built in to change attributes but if you do it for the virus then those files could be removed, damaged, or changed.

Return to top


Q and A

This site contains a lot of information. As with any publication not all information is available due to space, time, or subject constraints.

If you have a question that you did not find the answer on this web site  you a can ask your question here and we will endeavor to get you the most up to date answer possible!


Free Stuff!


Thank you for visiting my web site, and please come back again.

© www.diy-computer-repair.com '2008 Copyright Russell Enterprises All Rights Reserved
DiY Computer Repair contact support and sig. If you find this Web Site useful, feel free to recommend it to a friend.



Return to previous page



 
This website is not intended for children under the age of 18

Home
   Support   About owner   Site Map
Why I use SBI  Privacy Policy   Disclaimer

From the Desert South West ~ Arizona, USA
Copyright DIY-Computer-Repair.Com 2006-2011

powered-by-sbi



My Twitter! xml-rss Add to My Yahoo!
Add to My MSN Add to Google AddThis Social Bookmark Button My StumbleUpon Page Computer Blogs - BlogCatalog Blog Directory

Page copy protected against web site content infringement by Copyscape

 www.diy-computer-repair.com BBB Business Review


Site Sponsors

Once You Know, You Newegg
Electronic Parts
Save 20% on AVG Antivirus 2011 Professional
AVG kills viruses
Spyware and
Malware removal
Webroot Software Inc.


Need a battery for your Laptop?
All-Battery.com

Are you a Gamer?
GameStop.com

Laptop Accessories
LaptopZ.com - Your One-stop Laptop Parts Store!

Need an excellent CD/DVD burning program?

Buy Creator 2012 Today!
Kensigston Products


Fire that geek that is messing up your computer, you can do a better job.

More solutions in one place!

Self Computer Repair Unleashed

The Official  www.diy-computer-repair.com Reference manuals

Get yours Today!


Index
Home Page

How To's..
Auto Conf
Cleaning a computer
Change A File or Directory Attributes
Cleaning Your Keyboard
Create a bootable floppy
Create a bootable CD/DVD
Create a bootable USB device
Custom XP installation CD
WintoFlash for your USB Drive
Dual Boot for your computer
Installing a Hard Drive
Making an External Hard drive bootable
How to make a bootable USB hard drive
Build a BartPE disk
BartPE and ERD Commander
Crossover cable connection to transfer files.
Defragment your hard drive
Create an image of your hard drive
Creating a Symantec Ghost image
Restore Symantec Ghost image
Copy or Move a File?
Disaster Recovery
Connectors - What are they?
[Humor]
Installing new hardware, a how to...
Internet in your RV? Network Attached Storage NAS
Network Connection Speed
Overclocking - Processor and FSB
Partition and format a hard drive
Performance optimization
More...Performance optimization
Increased Security For Your Computer
Setup a Router
Wireless Router setup
Setup Software / Firewall
Windows Firewall Service
System Manager Tips
System Tools
Storage Manager
Services and Application
Upgrade your Motherboard
Backup for Windows XP