Jump to content

Recommended Posts

Posted

I thought i was getting the hang of this, but i must be missing something really obvious.

is there anyway i can tell it to go to a folder, then copy all files of a certain type? basically it would seem fine to me to use a function that would return all of the files of a certain type, for example if found a bit of code on a forum that used this:

$List = _FileSearch('h:\SD_VIDEO', '*.mod')

which would then mean that $list is everything in h:/sd_video that is a .mod file. however there isnt actually a function to do this is there? but the people on the forum seemed fine that it worked, am i missing something here? can you/do you have to build your own functions sometimes. a _filesearch() would be awesome!

could someone explain where i am going wrong?

  • Replies 43
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Grabbed from the Helpfile >_< Should copy all *.mod files from the currnet directory and dump them in C:\

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile("*.mod")

; Check if the search was successful
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

    FileCopy($file, "C:\*.*")

WEnd

; Close the search handle
FileClose($search)
Posted

ok thats cool, would that work in the example of a variable:

in my mind this should work:

$File = @ScriptDir & *.jpg

then later on you might be able to

filecopy($File , c:\)

but that doesnt work, it says i need a "WITH".

Posted

Change

$File = @ScriptDir & *.jpg
to
$File = @ScriptDir & "\*.jpg"

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

@eHash

Change

FileCopy($file, "C:\*.*")
to
FileCopy($file, "C:\")
because FileCopy needs a path according to the help file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

thats cool, that works now with the file copy, i thought that if i could do that then i could do the next bit. (filecopy is something i understand (although apparently not!))

i am wanting to create a program that i can use at home to send all of my files of one type that i need to work (or at least to my email). Ive managed to get hold of a smtp.au3 and i can get it to upload a single file with the correct name, but not using wild cards:

$File = @ScriptDir & "\*.txt"

_INetSmtpMailCom("smtp.gmail.com", $ToEmail, $ToEmail, $GmailUser, $GmailPass, $Body, $File)

this works and sends the email to my adderss but doesnt attach the file (there is nothing attached.)

i thought once i had figured out the copyfile bit it would be the same and i could simply put it accross.

Posted (edited)

hmm, everything has gone quiet! was that not worded very well?

Edited by AJJ
Posted

$File = @ScriptDir & "\*.txt"

_INetSmtpMailCom("smtp.gmail.com", $ToEmail, $ToEmail, $GmailUser, $GmailPass, $Body, $File)

_INetSmtpMailCom does not work with generic file names.

You could use something like:

$fl = _FileListToArray(@ScriptDir,"*.txt",1)
$attachements = ""
For $i = 1 to $fl[0]
  $attachements &= @ScriptDir & "\" & $fl[$i] & ";"
Next 
_INetSmtpMailCom($s_SmtpServer, "Senders Name",$FromAddress, $ToAddress, $s_Subject, Body = "", $Attachements,,,, $GmailUser, $GmailPass)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

what does the $attachment="" mean? what would go in there? because surely the actualy file is defined elsewhere (in the filelisttoarray?)

Posted (edited)

The list of files is in array $fl, $attachements = "" empties the variable (you don't have to change this line). In the loop the filenames taken from the array are prepended with the path and concatenated to a string separated with ";" into variable $attachements. _INetSmtpMailCon takes this variable and sends all files separated by a ";"

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

that was extremely complicated! but thanks!

what is $i = 1 and why does it need to & ";", also it says "unknown function name" at the _filelisttoarray

if i just try and translate what youve put in the code and just correct me if its wrong:

$fl = _FileListToArray(@ScriptDir,"*.txt",1) ; dear computer, please get a list of txt files in this directory and keep them in your hand for later

$attachements = "" ;i want to use a variable with the name attachments, but lets not fill it yet.

For $i = 1 to $fl[0]

  $attachements &= @ScriptDir & "\" & $fl[$i] & ";" ;the attachment is something plus the URL plus all those text files you found earlier ($i???)

Next 
_INetSmtpMailCom($s_SmtpServer, "Senders Name",$FromAddress, $ToAddress, $s_Subject, Body = "", $Attachements,,,, $GmailUser, $GmailPass); wisk _ the email off on your merry way to this address that i specify!

erm... yeah?

Posted

people always seem to use $i in everything, is there something special about it? its not really in the help files...

Posted

You want to send multiple files with _INetSmtpMailCom. _INetSmtpMailCom takes one parameter as the attachements to send.

The loop statement creates this parameter which has to be in the format "path\filename1;path\filename2"

The & is AutoIts concatenation operator. $i is a variable i (and sometimes others) use as an index variable - it's a(bad) habbit I've taken over from my PL/I (does anyone know this language >_<) programming times.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

ok cool, thats helpful, but why dont you think its working? did i say that it sends the email but not the attachment?

Posted

ok ive got it down to this:

[autoit] #include <SMTP.au3>

#Include <String.au3>

Global $Win, $Win2, $File, $Body, $ClearLogAfterEmail, $eFile, $GmailUser, $GmailPass, $ToEmail, $tStamp, $s_SmtpServer ;Delcare some variables

$File = @ScriptDir & "\*.txt" ;Name and place for the file

$Body = "file uploaded" ;The body of the email

$GmailUser = "***" ;Gmail login name (Required)

$GmailPass = "***" ;Gmail login pass (Required)

$ToEmail = "***" ;This is where the files will be sent

$s_Subject = "SCRIPT TEST"

$fl = _FileListToArray(@ScriptDir,"\*.txt",1)

$attachements = ""

For $i = 1 to $fl[0]

$attachements &= @ScriptDir & "\" & $fl[$i] & ";"

Next

_INetSmtpMailCom($s_SmtpServer,$GmailUser, $ToEmail, $s_Subject, $Attachements, $GmailUser, $GmailPass)

[autoit/]

but it still doesnt work, obviously i put in the user name and password etc. it says subscript used with non array variable. ahh!

Posted

could you translate what this bit means?

$fl = _FileListToArray(@ScriptDir,"\*.txt",1)

$attachements = ""

For $i = 1 to $fl[0]

$attachements &= @ScriptDir & "\" & $fl[$i] & ";"

Posted

The reason that you are getting that error is because the folder containing your script doesn't contain any .txt files so no array was created with _FileListToArray()

Oops. Also just noticed something else. That function call should be

$fl = _FileListToArray(@ScriptDir,"*.txt",1)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Posted

ok ive made sure that therre are txt documents in that folder, ive made sure ive changed that line you said about, now the errors gone away but it still doesnt work, nothing comes through on the email...

Posted

would it not just work if i got a function to define this filesearch, and then just simply ran this:

$List = _FileSearch('@scriptdir', '*.txt')

or isnt it as simple as that?

Posted

You would probably be re-inventing _FileListToArray()The problem now isn't in that part of your script anyway. It's something to do with adding the attachments to the email.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
×
×
  • Create New...