Jump to content

Help with DirRemove


Tech63
 Share

Recommended Posts

I will be using DirRemove Script to remove a Folder from various different users on different pc's.

The folder that needs deleted is in the same location on each pc.

C:Userscurrent logged-in userAppDataLocalTempFolder

Is there a wild card of some sort i can insert for current logged-in user?

so that for the same script will work regardless of what user is logged in.

 

I know, newbie question. I did some searching and couldn't come up with anything, may be just a common knowledge type thing.

Link to comment
Share on other sites

  • Moderators

Or @UserProfileDir (are you seeing yet how many ways there are to accomplish things with AutoIt) :)

DirRemove(@UserProfileDir & "\AppData\Local\Temp\Folder", 1)

Edit: Just thinking about Jos' initial question, if you wanted to do this remotely you could do something like this (path could easily be modified for XP):

$sPC = "JLVMWIN7_1"
$WMI = ObjGet("winmgmts:\\" & $sPC & "\root\CIMV2")
$aItems = $WMI.ExecQuery("SELECT * FROM Win32_ComputerSystem",Default,48)

    For $item In $aItems
        If $item.UserName <> "" Then
            $aSplit = StringSplit($item.UserName, "\")
            $uName = $aSplit[2]
        EndIf
    Next

$sDir = "C$\Users\" & $uName & "\AppData\Local\Temp\Folder"

DirRemove("\\" & $sPC & "\" & $sDir, 1)
Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

JLogan3o13, That did the trick, thanks! and i'll play around with the different methods mentioned as well. there is more to the script than the deletion of just 1 folder, so i'm sure ill run into something else along the way

thanks again

Link to comment
Share on other sites

By the way, the environment variable %temp% always points to the user's temp folder, so you can also use this.

DirRemove(EnvGet("temp") & "\Folder", 1)

Just in case they've moved their temp folder from the default location or a group policy has.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

This works for me in both XP and WIN7:

DirRemove(@UserProfileDir & "\My Documents\FOLDER", 1)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

@MyDocumentsDir

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

@MyDocumentsDir

 

True enough, but I was focusing on the OP's use of Envget. I was mistaken anyway, what I meant to post as an example was something like this:

This should run on XP or WIN7

MsgBox(0, "", EnvGet("userprofile") & "\My Documents")

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...