aa2zz6 Posted March 2, 2016 Share Posted March 2, 2016 (edited) The script currently grabs every extension *.* from the $NEO_folder directory and copies the files to $WebTMS directory. Is there a way to copy a layer name with different extension? One shapefile layer can have up to 7 extensions. I was hoping to copy certain layers and extensions rather than the entire directory. NEO_DIMP.cpg NEO_DIMP.prj NEO_DIMP.shp ect.. #include <FileConstants.au3> #include <File.au3> $NEO_folder = "C:\EIS\eis shape\NEO" ; Mapping Shapefiles $WebTMS = "C:\EIS\WebTMS" ; WebTMS Program folder $array = _FileListToArray($NEO_folder, "*.*", $FLTA_FILES) $count = 0 For $i = 1 To $array[0] $result = FileCopy($NEO_folder & "\" & $array[$i], $WebTMS,$FC_OVERWRITE) If $result = 1 Then $count +=1 Next MsgBox(0, "Files Copy", "Total Copied: " & $count &" Files") Edited March 2, 2016 by aa2zz6 Link to comment Share on other sites More sharing options...
InunoTaishou Posted March 2, 2016 Share Posted March 2, 2016 Store all the extensions you want to copy in an array $ext_to_keep[] = [".cpg", ".prj", ".shp"] Go through all the files in the folder and user _PathSplit to extract the extension. Then use _ArraySearch to see if the extension extract is in $ext_to_keep If (_ArraySearch($ext_to_keep, extension of file) > -1) Then Copy File EndIf Link to comment Share on other sites More sharing options...
aa2zz6 Posted March 2, 2016 Author Share Posted March 2, 2016 Thanks Inuno, I'll revise the script. Link to comment Share on other sites More sharing options...
AutoBert Posted March 2, 2016 Share Posted March 2, 2016 All extensions have the same length so there's no need for using _PathSplit: the native function StringRight will do the same job and is easier in handling and a little bit faster. Link to comment Share on other sites More sharing options...
TheSaint Posted March 2, 2016 Share Posted March 2, 2016 (edited) For $i = 1 To $array[0] $file = $array[$i] $fext = StringRight($file, 4) If $fext = ".cpg" Or $fext = ".prj" Then $result = FileCopy($NEO_folder & "\" & $file, $WebTMS,$FC_OVERWRITE) If $result = 1 Then $count +=1 EndIf Next Edited March 2, 2016 by TheSaint Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage) Link to comment Share on other sites More sharing options...
aa2zz6 Posted March 2, 2016 Author Share Posted March 2, 2016 (edited) Thanks for the comments and examples. I was able to use the stringleft to find certain shape file names and copy them to another directory without grabbing every file. Edited March 2, 2016 by aa2zz6 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