Script to transfer files from a folder based on a trigger

조회 수: 7 (최근 30일)
fadzhi
fadzhi 2021년 1월 18일
답변: Manas Shukla 2022년 5월 10일
Hi all,
For the problem below, i think the best solution is some bat script but i wanted to do this is Matlab. is it possible to write a script to achieve below:
Folder A, Folder B and Folder C
Folder C has 100 files marked as txt_1 to txt_100, whenever Folder A has a new file (i am using python to trigger a matlab code that outputs in A)
One file (txt_1) from Folder C should be copied to Folder B ....(for second new file in A, move txt_2 and so on....)
Many thanks in advance
Regards,
  댓글 수: 1
Mario Malic
Mario Malic 2021년 1월 18일
There are many questions that are same as yours, use search tool to find your answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Manas Shukla
Manas Shukla 2022년 5월 10일
As per my understanding of your issue, there are three folders, lest say Folder A, Folder B and Folder C. You want to write a MATLAB script which will copy a file from Folder C, in a systematic order, and paste it into Folder B whenever a new file is added in Folder A. You are using some Python code as trigger. I will bifurcate the workaround.
The first part is to check whether a new file is added to Folder A or not. For this you can refer to the below linked ML Answers Post. Detect New File in a Directory - (mathworks.com)
The second part is to copy a file from Folder C to Folder B. For that you can use the 'copyfile' command. Refer to the below example.
copyfile txt_1 'Folder B'
This will copy a file name 'txt_1' from current folder (i.e. Folder C) and paste it into Folder B. Link to 'copyfile' documentation is also attached here for your reference. Copy file or folder - MATLAB copyfile (mathworks.com)

카테고리

Help CenterFile Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by