pankajbokdia

Need to search in folder from CSV and copy/paste file to another folder

7 posts in this topic

Hello guys,

I am very new to AutoIt and I am working on a small project. I want to be able to read data from a CSV line, search for that term in a folder and then copy paste that file to another folder. Can you please give me a few pointers that could help me move in the right direction? Any help would be greatly appreciated. Thanks in advance! 

Share this post


Link to post
Share on other sites



FileCopy($FoundDir,$NewDir), when showing CSV i can give better answer.

Share this post


Link to post
Share on other sites

Thank you so much for the reply. 

Here is an example of the CSV file that I want to use. 

So just one function is enough? Sorry I am very new to this.

Regards

filename.csv

Share this post


Link to post
Share on other sites

If you know the filename then you could start with an If Then statement against the FIleExist function and the FileCopy functions. Example below.

#include <MsgBoxConstants.au3>

Local $iFileExists = "C:\Myfolder\Myfilename.csv"
Local $iFileDest = "C:\NewFolder\Myfilename.csv"

If $iFileExists Then
        FileCopy( $iFileDest )
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The file doesn't exist." & @CRLF & "FileExist returned: " & $iFileExists)
    EndIf

Links to Documentation for both.

https://www.autoitscript.com/autoit3/docs/functions/FileExists.htm

https://www.autoitscript.com/autoit3/docs/functions/FileCopy.htm

 

Share this post


Link to post
Share on other sites

Thank you for your reply. I will try and build the code from here 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

1 hour ago, pankajbokdia said:

So just one function is enough?

 

No, read file in a array using _FileReadToArray, Loop through Array, in each step use FileCopy.  This copies your files listed in CSV:

#include <File>
#include <Array>

Global $aFiles
Global $sSourceDir='c:\MySourceDir\'
Global $sDesDir='c:\NewDestination\'
Global $myCSV='PathToCSV_File'

_FileReadToArray($myCSV,$aFiles,$FRTA_COUNT)
_ArrayDisplay($aFiles)  ;can be deleted only for check the array

For $x = 0 to $aFiles[0]
    FileCopy($sSourceDir&$aFiles[$x],$sSourceDir&$aFiles[$x]
Next

Note: you have to correct the vars for your needs

Edit: please have a look in help about used functions!

 

@Nunos: FileCopy needs 2 params, have a look in your 2. link.

 

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

indeed

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