Sign in to follow this  
Followers 0
johann

Get foldernames in C:\Users

12 posts in this topic

#1 ·  Posted (edited)

Here is my task: I have to copy a file into a folder.

Sounds easy, but the folder is located in the useraccount folder.

My problem is now that I could use @username to copy the file into the currently logged in user folder, but I need to copy it into all user folders of users that were logged in on the machine.

Any suggestions would be appreciated.

Regards

Jo

Edited by johann

Share this post


Link to post
Share on other sites



Have a look at the marcos in the helpfile.


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Thx for the hint, but I didn't find something fitting my description as I checked the macros in the helpfile.

Could you tell me what exactly you mean?

Share this post


Link to post
Share on other sites

Which folder are you trying to copy it into? If it's a common folder such as the Start Menu or Desktop folder, you might be able to copy it once to the All Users folder, that way everyone will have access to it.


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

Share this post


Link to post
Share on other sites

It is a dll I have to copy to the users Lotus Notes data folder. Which is created on first start of notes in the Users profile. So copying it to All Users folder wouldn't solve my problem.

Share this post


Link to post
Share on other sites

Here's how I did it in a script I made a while ago.

#Include <File.au3>
#include <Array.au3>
Global $aUserList[10], $UserList[10]
If @OSVersion == "WIN_7" Or @OSVersion == "WIN_VISTA" Or @OSVersion = "WIN_2008" Then
    $NewOS = True
ElseIf @OSVersion == "WIN_XP" Then
    $NewOS = False
Else
    MsgBox(48, "Error", "Wrong OS version")
    Exit
EndIf
Global $X = 0
If Not $NewOS Then
    $UserList = _FileListToArray("C:Documents and Settings", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "NetworkService"
            Case $UserList[$I] = "LocalService"
            Case $UserList[$I] = "Administrator"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
Else
    $UserList = _FileListToArray("C:Users", "*.*", 2)
    For $I = 1 To $UserList[0]
        Select
            Case $UserList[$I] = "All Users"
            Case $UserList[$I] = "Default"
            Case $UserList[$I] = "Default User"
            Case $UserList[$I] = "Public"
            Case Else
                $aUserList[$X] = $UserList[$I]
                $X += 1
                If $X >= UBound($aUserList) Then
                    ReDim $aUserList[UBound($aUserList) + 10]
                EndIf
        EndSelect
    Next
EndIf
ReDim $aUserList[$X]
_ArrayDisplay($aUserList)

This will work on Windows XP, Vista, 7 and Server 2008 but can be modified for other versions fairly easily. It doesn't include the standard default profile paths in the array, such as All Users, Administrator, DefaultUser, etc.


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

Share this post


Link to post
Share on other sites

Hi, johann. Rather than trying to hit the folder of everyone who has logged into the machine, have you thought of just writing your script to copy the file name, using the @username variable as you mention, and then putting the script into the startup menu? Then it will be done for each user automatically when they login. This way, not only would you resolve the issue for any current local user, but would take care of any new profiles created in the future.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Very good point JLogan3o13.


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

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

johann,

IF you cannot use JLogan3o13's suggestion, here is some code that will show all folders below C:USERS. This will only show the next level, but can be changed easily enough to recurse all levels.

#include<array.au3>
local $folder_list = r_search('c:users')
_arraydisplay($folder_list)
Func r_search ($s_dir)
local $folders[1]
local $files = FileFindFirstFile($s_dir & "*.*")
If @error Then msgbox(0,'Filefindfirst Error',@error)
While 1
  $next = FileFindNextFile($files)
  If @error Then return($folders)
  If @extended then
   $folders[ubound($folders)-1] = $s_dir & '' & $next
   redim $folders[ubound($folders) + 1]
  EndIf
WEnd
FileClose($files)
EndFunc

Good Luck,

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

johan,

This code changed slightly to include folder recursion. See commented line.

#include<array.au3>

local $st = timerinit()
local $folders[1]

local $folder_list = r_search('c:users')

consolewrite('Time to list folders = ' & round(timerdiff($st)/1000,4) & @lf)

_arraydisplay($folder_list)

Func r_search ($s_dir)

    local $files = FileFindFirstFile($s_dir & "*.*")
    If @error = -1 Then msgbox(0,'Error','')

    While 1
        $next = FileFindNextFile($files)
        If @error Then return($folders)
        If @extended then
            $folders[ubound($folders)-1] = $s_dir & '' & $next
            redim $folders[ubound($folders) + 1]
            consolewrite($s_dir & '' & $next & @lf)
            ;r_search($s_dir & '' & $next)             ; uncomment this line to recurse folders
        EndIf
    WEnd
    FileClose($files)

EndFunc

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Hi guys, thanks for the replies. I really appreciate your help. Yesterday I started working with BrewMan's suggestion and added a few lines of code (just to use the array in the way I needed). What can I say, it works very well.

@JLogan3o13: Thats what I thought about in the first place, but I am not very into startscripts and try to avoid using them as much as I can. We have not that much changing user logins on our clients so this is not that much of concerning.

Thanks again for your help

Johann

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

This was very usefull for me. I have managed to plagarise it for a process I needed and include it now for anyone else use or further comments/amendments. (BTW this searchs voer 2000 sub folders)

Thanks, Phil

#include<array.au3>
#Include <Excel.au3>
local $folder_list = r_search('P:TspiritUser')
;local $folder_list2 = r_search('P:TspiritUser')

;_arraydisplay($folder_list)
FileDelete("P:TspiritUserPAYEBACSLOG.CSV")
Func r_search ($s_dir)
local $folders[1]
local $files = FileFindFirstFile($s_dir & "*.*")
If @error Then msgbox(0,'Filefindfirst Error',@error)
While 1
  $next = FileFindNextFile($files)
  If @error Then return($folders)
  If @extended then
   $folders[ubound($folders)-1] = $s_dir  & $next
   redim $folders[ubound($folders) + 1]
  EndIf
WEnd
FileClose($files)
EndFunc

$end = _ArrayMaxIndex($folder_list)
;MsgBox(4096,"End",$end)
$n = 0
$count = 0
ProgressOn("Progress Meter", "Increments every second", "0 percent")
While $n < $end
    $n = $n + 1
;$folder_list[$n] = $folder_list[$n] & "PAYEBYBACS.EXT"
    if FileExists($folder_list[$n] & "PAYEBYBACS.EXT") Then
        $count = $count + 1
        ;MsgBox(4096,"File",$folder_list2[$n] & "PAYPBACS.EXT")
        ;MsgBox(4096,"File",$folder_list[$n] & "PAYEBYBACS.EXT")
        $ShortCode = StringRight($folder_list[$n],3)
        FileWrite("P:TspiritUserPAYEBACSLOG.CSV", $ShortCode &  @CRLF)
        FileClose("P:TspiritUserPAYEBACSLOG.CSV")
        FileCopy($folder_list[$n] & "PAYEBYBACS.EXT",$folder_list[$n] & "PAYPBACS.EXT",1)
        FileDelete($folder_list[$n] & "PAYEBYBACS.EXT")

        EndIf

ProgressSet(100/$end * $n ,"Done", "Complete")


WEnd
ProgressOff()

MsgBox(4096,"The End","This is now complete")
_ExcelBookOpen("P:TspiritUserPAYEBACSLOG.CSV")
Edited by PhilBall

Share this post


Link to post
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
Sign in to follow this  
Followers 0