3

So, I bought this book called "Learn Python the Hard Way" and in the learning progress as it is my first programming language.

The problem I'm facing now is I couldn't create a directory in Powershell for Windows 7. I followed exactly like what the book said "mkdir mystuff" and I got the following error.

All I want is to make the directory becomes like this

C:\Documents and Settings\User\mystuff 

How do I solve this ? Your help is greatly appreciated.

Everything works fine in WindowsXP but not Windows 7.

    PS C:\Windows\System32\WindowsPowerShell\v1.0> mkdir mystuff
    New-Item : Access to the path 'mystuff' is denied.
   At line:38 char:24
    +         $scriptCmd = {& <<<<  $wrappedCmd -Type Directory @PSBoundParameters
    }
         + CategoryInfo          : PermissionDenied: (C:\Windows\Syst...ll\v1.0\mys
      tuff:String) [New-Item], UnauthorizedAccessException
     + FullyQualifiedErrorId : CreateDirectoryUnauthorizedAccessError,Microsoft
   .PowerShell.Commands.NewItemCommand
2
  • Well you don't have the permissions to create that directory. Either elevate your privileges using UAC or create a directory somewhere you're allowed to write Commented Jul 3, 2012 at 13:15
  • "learn python the hard way" - is the "hard" part about using powershell? i would advise you to use cygwin, which brings you the power of a linux shell to the windows desktop (and has python already included). Commented Jul 3, 2012 at 13:20

3 Answers 3

5

Windows is preventing you from adding a directory to the System32 folder. You don't have permission to do so by default, because really you shouldn't do that.

Instead try changing directory to somewhere more reasonable and making the directory there. %UserProfile% is an alias for your home directory.

cd %UserProfile%
mkdir mystuff

The reason this works in XP, by the way, is that XP isn't very strict about security or permissions. Which is wrong. : )

Sign up to request clarification or add additional context in comments.

2 Comments

%USERPROFILE% should point to a writable path on all Windows systems. If you need the full path, it's probably something like C:/Users/[username]
Heh although %HOME% looks right I could only get %UserProfile% to work in WinXP...? <Haha now this comment makes no sense>
2

Based on the prompt you're trying to create a folder in the PowerShell directory path and you don't have the appropriate permissions to do so. Try this instead:

mkdir $env:USERPROFILE\mystuff

Comments

0

If you wanted to create the directory C:\Documents and Settings\User\mystuff, try to be explicit about it:

cd "C:\Documents and Settings\User\"
mkdir mystuff

Have fun learning Python. :-)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.