Jump to content
Sign in to follow this  
AJJ

File Search

Recommended Posts

AJJ

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?

Share this post


Link to post
Share on other sites
eHash

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)

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
water

Change

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


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
water

@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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AJJ

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.

Share this post


Link to post
Share on other sites
AJJ

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

Edited by AJJ

Share this post


Link to post
Share on other sites
water

$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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AJJ

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?

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
AJJ

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!

Share this post


Link to post
Share on other sites
AJJ

could you translate what this bit means?

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

$attachements = ""

For $i = 1 to $fl[0]

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

Share this post


Link to post
Share on other sites
GEOSoft

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!"

Share this post


Link to post
Share on other sites
AJJ

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

Share this post


Link to post
Share on other sites
AJJ

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?

Share this post


Link to post
Share on other sites
GEOSoft

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!"

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  

×