aa2zz6

FileCopy Extensions

6 posts in this topic

#1 ·  Posted (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 by aa2zz6

Share this post


Link to post
Share on other sites



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

 

Share this post


Link to post
Share on other sites

Thanks Inuno, I'll revise the script. 

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

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)

userbar.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (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 by aa2zz6

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