Nunos Posted July 29, 2011 Share Posted July 29, 2011 I suspect this is a really simple question but I am struggling with it. So I am trying to check if a PDF exists after I create a new version of it in my script. The PDF name will change because the date and time are appended to the file name such as SalesReport_07292011_1620 so I tried to use fileexists with SalesReport_* in hopes that the * wildcard would return the file and allow me to FileMove to the servers Reports folder. This is my second attempt at making a script so I am not knowledgeable but I am a fairly quick study if someone has some time to help me.Thank you in advance for your time. Link to comment Share on other sites More sharing options...
PowerCat Posted July 29, 2011 Share Posted July 29, 2011 (edited) Is there only one file in the folder? You can probably use "_FileListToArray" and then process the array and use StringRight to check if the extension is a PDF, or something. Comic sans! Or to move all PDF, just use the _FileListToArray and FileMove each array entry Edited July 29, 2011 by PowerCat Link to comment Share on other sites More sharing options...
Nunos Posted July 29, 2011 Author Share Posted July 29, 2011 Thank you PowerCat. You are correct there will be lots of PDF's in the folder everyday to move to the server and they will always have a different name. Sorry for the Comic sans Link to comment Share on other sites More sharing options...
PowerCat Posted July 29, 2011 Share Posted July 29, 2011 Thank you PowerCat.You are correct there will be lots of PDF's in the folder everyday to move to the server and they will always have a different name.Sorry for the Comic sans Haha it's just funny to see comic sans, usually people don't change the font So just create an array of all the files in the folder with _FileListToArray and then use a For loop to FileMove each array entry, that should work. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 29, 2011 Moderators Share Posted July 29, 2011 (edited) I agree with _FileListToArray(), however, if you just want a single match then you could do something like:Global $gs_Dir = @ScriptDir Global $gs_Mask = "SomeMask*" Global $gs_ReturnedFile = _FileMaskExist($gs_Dir, $gs_Mask, 1) MsgBox(64 + 262144, "Info", "Error: " & @error & @CRLF & "File: " & $gs_ReturnedFile) ; $i_flag: 0 = search for file or directory, 1 = Files only, 2 = directory only Func _FileMaskExist($s_dir, $s_mask = "*", $i_flag = 0, $f_fullpath = True); will only return 1 match $s_dir = StringRegExpReplace($s_dir, "[\\/]+\z", "") & "\" Local $h_search = FileFindFirstFile($s_dir & $s_mask) If @error Or $h_search = -1 Then Return SetError(1, 0, "") Local $s_file = FileFindNextFile($h_search) If @error Then Return SetError(2, 0, "") Local $i_ext = @extended FileClose($h_search) If Not $f_fullpath Then $s_dir = "" Switch Int($i_flag) Case -1, 0 Return $s_dir & $s_file Case 1 If $s_file And Not $i_ext Then Return $s_dir & $s_file EndIf Case Else If $s_file And $i_ext Then Return $s_dir & $s_file EndIf EndSwitch Return SetError(3, 0, "") EndFunc Edited July 29, 2011 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now