Take Ownership and Grant ‘Full Control’ Recursively

Take Ownership KB ID 0001200 

Problem

I had a bunch of old user profile folders I needed to delete today, When setup properly even the domain administrator can’t get in there and delete them;

You need permission to perform this action.

You don’t currently have persmission to access this folder

If it’s just one folder then simply take ownership, grant yourself rights and delete it! But I had a lot of folders so I needed a more robust (read less work) solution.

Solution: Take Ownership

Take Ownership of all Folders/Sub-Folders, and Files

Open an administrative command window, and execute the following command;

[box]

takeown /a /r /d Y /f C:\"Path-To-Folder"

[/box]

Grant ‘Full Control’ Rights to all Folders/Sub-Folders, and Files

Just because you are the owner, that does not mean you have any rights to the folders and files, to grant full control to the administrators group.

[box]

icacls C:\"Path-To-Folder" /grant administrators:F /t

[/box]

You can then delete the folder and its contents recursively with the following command.

[box]

Remove-Item -Path "Path-To-Folder" -Force -Recurse

[/box]

Related Articles, References, Credits, or External Links

Can’t Delete a File or Folder or Take Ownership

Rename / Change all File Extensions In a Folder and All Subfolders Recursively

KB ID 0000896 

Problem

I long time ago this site was hosted in my dining room, on a PC under my desk. I was running Windows and IIS. When I moved the site to a hosted Apache Linux server, I discovered that Linux is a little more rigid on its rules for file extensions. For example in Windows .JPG and .jpg is the same thing, but on a Linux box that’s NOT the case.

As I’ve used the Windows Snipping Tool a lot in the past my older images have a .JPG or .PNG extension, if your websites URL’s point to filename.jpg, then the URL will work in Windows but it WON’T work on a Linux web server (in my case Apache).

I fixed all the broken URL’s a long time ago, but the file extensions remained. This annoyed my Technical OCD, so this afternoon I decided to rename all the .JPG files to .jpg, and all the .PNG files to .png.

Note: I changed all the URL’s with a a simple file and replace in Dreamweaver.

Solution

To rename all the files in a folder simply use the ren or the rename command;

[box]

ren *.JPG *.jpg
Note: If you wanted to change all the extensions to something else that's fine too e.g.

ren *.htm *.txt

[/box]

The limitation is you cannot do the same if you have folders and subfolders, you need to rename all the file extensions recursively. To do that use the following syntax.

[box]

forfiles /S /M *.JPG /C "cmd /c rename @file @fname.jpg"

Note: As Above, if you wanted to change all the extensions to something else that's fine too e.g.

forfiles /S /M *.JPG /C "cmd /c rename @file @fname.jpg"

[/box]

So to fix my problem I only needed two commands.

Related Articles, References, Credits, or External Links

NA