Jump to content

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


Recommended Posts

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! 

Link to comment
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

 

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...