Link to home
Start Free TrialLog in
Avatar of Luis Diaz
Luis DiazFlag for Colombia

asked on

Batch or VBscript: Transfer/replace files if they exist from one folder to other folders.

Hello Experts,

I am looking for a Batch or a VBS script that covers the following needs :

I have a Root folder C:\Root in which I have specific files ie C.jar, T.jar, A.jar and another folder with the following Name C:\Interface.

In this C:\Interface folder there are multiple folders interface1, interface2 etc…
Every subfolder have a lib folder it can be located in a sub-folder (level-1) or sub-sub-folder (level-2)

What I want is to launch a Batch and or a VBS in which I will be able to report based on a csv config file or directly in the batch or VBS file (the best will be a config csv file with the information reported bellow) and transfer (replace) all the files in C:\Root folder if they exist in sub levels of C:\Interface folder.



The config file should have the following parameters:

•      Source_Folder (folder in which are located the files that I want to transfer)
•      Source_Files (files that I want to replace located in Source_Folder)
•      Destination_Folder (Top level in which is located my folders which contains the subfolders composed by the files that I want to replaced from Source_Folder

The tricky thing is that the files can be in a sub-level2 or sub-level3 the folders located in Destination_Folder as a result the script should be able to recursively drill down sub-folder of Destination_Folder and check if they exist if so Replace the reported files.


Example of config file

Source_Folder; Source__Files ; Destination_Folder
C:\Source; C.jar,T.jar, A.jar;C:\Interface


I put a semicolon to distinguish fields of config file and a comma “,” to distinguish the files reported in Source_Files, if this is not ok don’t hesitate to modify it.

If you have questions, please don’t hesitate to contact me.

Thank you very much for your help.
Avatar of Anastasia D. Gavanas
Anastasia D. Gavanas
Flag of Greece image

You need a script that will check new folder / old folder

Set fso=CreateObject("Scripting.FileSystemObject")
source="d:\path1\"
target="d:\path2\"

Set fldr=fso.getFolder(source)
for each file in fldr.files
        call mover(lcase(file.path))
next

sub mover(f1)
        f2=f1
        if fso.fileExists(f2) then
                fso.MoveFile f1,target
                fso.MoveFile f2,target
                wscript.sleep 60000
        end if
end sub

Open in new window


We will need to add conditions here I guess - can you post a sample of your csv file?
Avatar of Luis Diaz

ASKER

Thank you for this proposal.

Please find attached the config csv file.
config_move_files.csv
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you very much for this proposal.
Unable to test it today. I will test it tomorrow.
Thank you again.
Sorry for the delay, unable to test it. I will try to test it before Monday.
Thank you.
Sorry for the delay. I tested and it works!! Thank you very much for your help!