Options

Batch file help

BokehBokeh Member Posts: 1,636 ■■■■■■■□□□
I have several users who have files installed on their desktop that we want to copy to a specific area on their machine and clean up the desktop.

Since everyone has their own login and machine name, I am having trouble getting the file to work.

I am wondering if there is a way to use a wildcard that will use the current user logged on and complete the process?

Files are at c:\documents and settings\jsmith\desktop\xxx.xxx as an example. I want to find a way that I can write one batch program and not have to change it for each individual user name.

Comments

  • Options
    DevilsbaneDevilsbane Member Posts: 4,214 ■■■■■■■■□□
    %username% is a variable that substitutes the current user logged on in. Works like a charm, I use it all the time!

    "c:\documents and settings\%username%\desktop\file.txt" and don't forget the quotes around the whole thing.
    Decide what to be and go be it.
  • Options
    DevilsbaneDevilsbane Member Posts: 4,214 ■■■■■■■■□□
    Open up a command prompt and type "set" (without the "" and hit enter)

    This will output a list of all of the enviornmental variables. You will see username and computername in this list to name the two that I used the most.

    You could also use %userprofile%\desktop\file.txt and in that case you don't need the quotes since there are no spaces, but it still doesn't hurt to use them. Personally I always do it with the %username% variable.
    Decide what to be and go be it.
  • Options
    tierstentiersten Member Posts: 4,505
    Devilsbane wrote: »
    %username% is a variable that substitutes the current user logged on in. Works like a charm, I use it all the time!

    "c:\documents and settings\%username%\desktop\file.txt" and don't forget the quotes around the whole thing.
    If you're trying to find their profile directory then use %UserProfile% instead of hardcoding "Documents and Settings" + %Username% as it is not guaranteed that it will always be there. e.g. The default location was changed to \Users\ in Vista and above.

    "%UserProfile%\Desktop\Blahblah.txt"
Sign In or Register to comment.