Jump to content

FileFindFirstFile/FileWrite


Recommended Posts

hello,

I'm writting an autoit script to copy the names of all the folders in C:\usersfolders and then write the name into my script.

with :

$search = FileFindFirstFile("C:\test\*.*")

$script = FileOpen("C:\test.txt", 1)

If $script = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

FileWrite($script, $file)

WEnd

FileClose($search)

FileClose($script)

I managed to get those folder names and write them in my text file.

but they just write to where ever the cursor was last set before the save.

I would like to add 2 things to this autoit script.

1) to add my script into the line and simply put $file and type the rest of my line.(e.i FileWrite ("this is my script" $file "this is the rest of my script")

2)and for each name found with the $search variable to have the FileWrite write the same text but on a different line and with the next name found

and so on so that my script file would look like :

setacl -on "C:\users\$file1" -ot file -rec cont_obj -actn setowner -ownr "C:users\$file1;s:n"

setacl -on "C:\users\$file2" -ot file -rec cont_obj -actn setowner -ownr "C:users\$file2;s:n"

setacl -on "C:\users\$file3" -ot file -rec cont_obj -actn setowner -ownr "C:users\$file3;s:n"

setacl -on "C:\users\$file4" -ot file -rec cont_obj -actn setowner -ownr "C:users\$file4;s:n"

setacl -on "C:\users\$file5" -ot file -rec cont_obj -actn setowner -ownr "C:users\$file5;s:n"

setacl -on "C:\users\$file6" -ot file -rec cont_obj -actn setowner -ownr "C:users\$file6;s:n"

where $file1 to 6 represents the 6 folder names that would be in C:\test

Thank you for your help.

Link to comment
Share on other sites

but they just write to where ever the cursor was last set before the save.

That's because you opened the file in Append mode. Open it with flag 2 isntead of 1 to erase previous content.

I would like to add 2 things to this autoit script.

1) to add my script into the line and simply put $file and type the rest of my line.(e.i FileWrite ("this is my script" $file "this is the rest of my script")

2)and for each name found with the $search variable to have the FileWrite write the same text but on a different line and with the next name found

and so on

What?

Link to comment
Share on other sites

That's because you opened the file in Append mode. Open it with flag 2 isntead of 1 to erase previous content.

What?

As of now the autoit script is reading the name of the folders from "C:\users" and copying the name one by one.

my folder structure is as follows:

C:\users\user1

C:\users\user2

C:\users\user3

C:\users\user4

The folder "User" has been created for users from my AD to send there print jobs to. I would like to change the quota limit for each of these folders.

If there is a way to do that with autoit that would be great, is there?

Or else I can use the autoit script to build my *.bat file.

which looks like:

setacl -on "C:\users\$user1" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user1;s:n"

setacl -on "C:\users\$user2" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user2;s:n"

setacl -on "C:\users\$user3" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user3;s:n"

setacl -on "C:\users\$user4" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user4;s:n"

the script :

$search = FileFindFirstFile("C:\test\*.*")

$script = FileOpen("C:\test.txt", 1)

If $script = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

FileWrite($script, $file)

WEnd

FileClose($search)

FileClose($script)

simply copies the name of the folder and pastes into anytext file I want.

I would like it to create a *.bat, open it (edit) and then paste the name of the folder within the line of my script where the variable is needed and then for each name found by the variable reprint the line.

so for example, my user folder called User1

would copy the name of the folder and paste it (user1) into the script line:

setacl -on "C:\users\$user1" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user1;s:n"

after having done so I would like it to take the next folder name (user2) and paste into the same text on a different line:

setacl -on "C:\users\$user2" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user2;s:n"

Thank you,

Edited by johnyV
Link to comment
Share on other sites

Hi!

GetFileSecurity/SetFileSecurity APIs

Those will help you. But you have much googling/experimenting to do.

Msdn will give you good info on all but the values of names...

Just google names of variables and other sites will give you values...

/Manko

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

Hi!

GetFileSecurity/SetFileSecurity APIs

Those will help you. But you have much googling/experimenting to do.

Msdn will give you good info on all but the values of names...

Just google names of variables and other sites will give you values...

/Manko

"GetFileSecurity/SetFileSecurity APIs" these are autoit commands?

Link to comment
Share on other sites

"GetFileSecurity/SetFileSecurity APIs" these are autoit commands?

Nope they are windows api calls. You have to "DllCall" them.

Begin to look at MSDN for those...

Haven't seen anything on file/folder security, native or UDF for autoit.

But I'm NO expert, and not always well informed...

/Manko

Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

Nope they are windows api calls. You have to "DllCall" them.

Begin to look at MSDN for those...

Haven't seen anything on file/folder security, native or UDF for autoit.

But I'm NO expert, and not always well informed...

/Manko

Manko, I already plan on using the setacl command. It works perfectly but I will have a 150 folders to type in my script and it will take forever, so I would like autoit to build my script for me.

can you help me do this :::::::::(3rd Post)

I would like it to create a *.bat, open it (edit) and then paste the name of the folder within the line of my script where the variable is needed and then for each name found by the variable reprint the line.

so for example, my user folder called User1

would copy the name of the folder and paste it (user1) into the script line:

setacl -on "C:\users\$user1" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user1;s:n"

after having done so I would like it to take the next folder name (user2) and paste into the same text on a different line:

setacl -on "C:\users\$user2" -ot file -rec cont_obj -actn setowner -ownr "C:users\$user2;s:n"

Thanks.

Edited by johnyV
Link to comment
Share on other sites

Hi!

What you are proposing is not really hard. But you REALLY not to start working for yourself.

It is just manipulating strings and writing to file. All that IS handled in the helpfiles.

The rest is experimenting till it works. If you get stuck, please come back! :D

[EDIT: First line: NOT=NEED]

/Manko

Edited by Manko
Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually...
Link to comment
Share on other sites

Hi!

What you are proposing is not really hard. But you REALLY not to start working for yourself.

It is just manipulating strings and writing to file. All that IS handled in the helpfiles.

The rest is experimenting till it works. If you get stuck, please come back! :D

[EDIT: First line: NOT=NEED]

/Manko

wow thats suppose to be help and support....

Obviously if I took the time to write in the forum, I`m not really sure what to do from that point...and maybe it is easy for you but I`m still new to this program.

No thanks.

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...