Forum Discussion

Waqaarahsab's avatar
Waqaarahsab
Copper Contributor
Oct 21, 2020
Solved

How to make a file in localappdata location using powershell

I am trying to create a file in the localappdata location in powershell. i have tried using $env:localappdata but it just shows the localappdata location just like write-host C:\Users\%username%\AppData\Local. I want to go to that location but it cant be done like in cmd i can just do cd %localappdata%. My main goal is to create a file there and delete it at certain condition. How do I change directory to %localappdata% location? 

  • Waqaarahsab 

    if you want to change the current directory to go to AppData, try set-location $env:LOCALAPPDATA

    if you want to write content to the folder

    did you try something like this

    New-Item -Path "$($env:LOCALAPPDATA)\NewContent.txt"

3 Replies

  • farismalaeb's avatar
    farismalaeb
    Steel Contributor

    Waqaarahsab 

    if you want to change the current directory to go to AppData, try set-location $env:LOCALAPPDATA

    if you want to write content to the folder

    did you try something like this

    New-Item -Path "$($env:LOCALAPPDATA)\NewContent.txt"
    • Ctakacowsi's avatar
      Ctakacowsi
      Copper Contributor

      Hello,

      I have a similar issue where I am trying to change the path to point to a folder on c:/ but it's not accepting the command? Could you provide me details on how to correct my mistake?

       

      I've added images, I'm looking to point to a folder on the c:/

Resources