Jump to content
KickStarter15

Save created file in multiple folders

Recommended Posts

KickStarter15

Hi Experts,

I'm stuck with my current scripting right now and I already searched for help in autoit but seems no topic found for my problem.

I would like to ask again for your expertise and idea on how to handle below.

First, I have created a folder in drive "D:\Programs\Test\@username\" in that folder there are three users found "user1", "user2", and "user3". Now, I want to gave them instructions using _FileCreate() and save it to each user.

Question: Is it possible that when using GUICtrlRead($Input) can read these users and can code do the saving in their folder? users will be inputting usernames in input box to save instructions. Would that be possible?:(

So far, I have my below code:

#include <GUIConstants.au3>
#include <File.au3>
#include <FileConstants.au3>

$MainGUI = GUICreate("Do Some Stuff", 202, 95, -1, -1)
$Input = GUICtrlCreateInput("", 8, 8, 185, 21)
$iWrite = GUICtrlCreateButton("Save", 8, 65, 57, 25, 0)
DirCreate("D:\Programs\Test\" & @UserName & "\")
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $iWrite
            $sPath = "D:\Programs\Test\" & GUICtrlRead($Input) & "\"
            $fCreate = _FileCreate($sPath&GUICtrlRead($Input)&"_Instructions")
            $sSave = $sPath&GUICtrlRead($Input)&"_Instructions"
            If GUICtrlRead($Input) = "user1" Then
               FileWriteLine($sSave, "Step1: Word Count")
               FileWriteLine($sSave, "Step2: Word Count")
               FileWriteLine($sSave, "Step3: Word Count")
               FileWriteLine($sSave, "Step4: Word Count")
            EndIf
            MsgBox("","","Done!")
            Exit
    EndSwitch
WEnd

This code can only save to one folder "user1" but i need to save it to all three users. I have attached sample screenshot for details.

- user1 is the @Username, same for in user 2 and 3.

Thank you in advance, experts. I know someone here has idea how. I'm just a newbie, and so far I'm learning!:D

InputBox.png


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

What do you mean " user1 is the @Username, same for in user 2 and 3. "?

Share this post


Link to post
Share on other sites
Subz

Do you mean something like:

#include <GUIConstants.au3>
#include <File.au3>
#include <FileConstants.au3>

Local $sSavePath = "D:\Programs\Test\" & @UserName & "\"
If FileExists($sSavePath) = 0 Then DirCreate($sSavePath)

Local $sSteps = ""
$sSteps &= "Step1: Word Count"
$sSteps &= "Step2: Word Count"
$sSteps &= "Step3: Word Count"
$sSteps &= "Step4: Word Count"

$hGUI = GUICreate("Do Some Stuff", 202, 95, -1, -1)
$idUserIds = GUICtrlCreateInput("", 8, 8, 185, 21)
$idSave = GUICtrlCreateButton("Save", 8, 65, 57, 25, 0)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $idSave
            UserWrite()
            MsgBox("","","Done!")
            Exit
    EndSwitch
WEnd

Func UserWrite()
    $aInput = StringSplit(GUICtrlRead($idUserIds), ',')
    For $i = 1 To $aInput[0]
        $hFileOpen = FileOpen($sSavePath & $aInput[$i] & "_Instructions", 10)
        FileWrite($hFileOpen, $sSteps)
        FileClose($hFileOpen)
    Next
EndFunc

 

Share this post


Link to post
Share on other sites
KickStarter15

Hi Subz,

Thanks for your response.

14 hours ago, Subz said:

What do you mean " user1 is the @Username, same for in user 2 and 3. "?

There are three users in the same path "$sSavePath". user1 represents the value of @Username, like user1 "dthomas", user2 "atorres", and user3 "kfua". Now, these three users must have the same instruction that will be saved at their folder at the same time. It's like you will distribute the _FileCreate() in their folder.

14 hours ago, Subz said:
#include <GUIConstants.au3>
#include <File.au3>
#include <FileConstants.au3>

Local $sSavePath = "D:\Programs\Test\" & @UserName & "\"
If FileExists($sSavePath) = 0 Then DirCreate($sSavePath)

Local $sSteps = ""
$sSteps &= "Step1: Word Count"
$sSteps &= "Step2: Word Count"
$sSteps &= "Step3: Word Count"
$sSteps &= "Step4: Word Count"

$hGUI = GUICreate("Do Some Stuff", 202, 95, -1, -1)
$idUserIds = GUICtrlCreateInput("", 8, 8, 185, 21)
$idSave = GUICtrlCreateButton("Save", 8, 65, 57, 25, 0)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $idSave
            UserWrite()
            MsgBox("","","Done!")
            Exit
    EndSwitch
WEnd

Func UserWrite()
    $aInput = StringSplit(GUICtrlRead($idUserIds), ',')
    For $i = 1 To $aInput[0]
        $hFileOpen = FileOpen($sSavePath & $aInput[$i] & "_Instructions", 10)
        FileWrite($hFileOpen, $sSteps)
        FileClose($hFileOpen)
    Next
EndFunc

 

The code you have will create a file named "dthomas;atorres_Instructions" and will be saved only in first user "dthomas" but not to "atorres" folder. See attached for the result of your code.

FileCreate.png


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
KickStarter15

I need to have something like this:

If GUICtrlRead($Input) = "dthomas;atorres;kfua" Then
;do the file create and save it to these three users at their folders
endif

Would that be possible? :sweating:


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

You mean like this:

#include <GUIConstants.au3>
#include <File.au3>
#include <FileConstants.au3>

Local $sSavePath = "D:\Programs\Test\"
If FileExists($sSavePath) = 0 Then DirCreate($sSavePath)

Local $sSteps = ""
$sSteps &= "Step1: Word Count"
$sSteps &= "Step2: Word Count"
$sSteps &= "Step3: Word Count"
$sSteps &= "Step4: Word Count"

$hGUI = GUICreate("Do Some Stuff", 202, 95, -1, -1)
$idUserIds = GUICtrlCreateInput("dthomas;atorres;kfua", 8, 8, 185, 21)
$idSave = GUICtrlCreateButton("Save", 8, 65, 57, 25, 0)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $idSave
            UserWrite()
            MsgBox("","","Done!")
            Exit
    EndSwitch
WEnd

Func UserWrite()
    $aInput = StringSplit(GUICtrlRead($idUserIds), ';')
    For $i = 1 To $aInput[0]
        $hFileOpen = FileOpen($sSavePath & $aInput[$i] & "\" & $ainput[$i] & "_Instructions", 10)
        FileWrite($hFileOpen, $sSteps)
        FileClose($hFileOpen)
    Next
EndFunc

 

Edited by Subz
Removed _ArrayDisplay
  • Like 1

Share this post


Link to post
Share on other sites
KickStarter15

Yup, just the way it is Subz.... :lol:

Thank you so much for your quick response. I knew it is so simple for you to create the code like this. I'll study more coding like this to enhance my idea and be like you someday and others that are experts.

Thank you so much Subz.:D


Programming is "To make it so simple that there are obviously no deficiencies" or "To make it so complicated that there are no obvious deficiencies" by C.A.R. Hoare.

Share this post


Link to post
Share on other sites
Subz

No problem, glad to assist.

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

×