Recursively search in sub folders and move files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Recursively search in sub folders and move files

#1 Post by Danny » 06 Jan 2014 15:34

Hi,

This codes are moving the files from soruce folder to destination perfectly.

Code: Select all

@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%" & set "Min=%dt:~10,2%" & set "Sec=%dt:~12,2%"

set "datestamp=%DD%%MM%"

for /l %%a in (0) do (
    if exist "C:\test\1*%datestamp%.*" move "C:\test\1*%datestamp%.*" "D:\report"
    if exist "C:\test\TR%datestamp%.*" move "C:\test\TR%datestamp%.*" "D:\report"
    ping -n 60 localhost > nul
)


But now i want this codes to search recursively in multiple sub-folders. The folder structure is in this format.
C:\Repository\000\todays date(dd-mm-yyyy)\upload\file1 and file2
C:\Repository\001\todays date(dd-mm-yyyy)\upload\file1 and file2
C:\Repository\002\todays date(dd-mm-yyyy)\upload\file1 and file2

To move the files from this sub folder upload to D:\report search for files every 60 seconds.
The first file will never be in duplicate so no issue of overwriting the file in destination folder, but the second file can be duplicate so how to overcome that issue. can we create a merge file in destination folder. They are text files.

Sorry for asking to much.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Recursively search in sub folders and move files

#2 Post by foxidrive » 06 Jan 2014 19:18

Please provide better details for the filenames

Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Re: Recursively search in sub folders and move files

#3 Post by Danny » 06 Jan 2014 22:02

foxidrive wrote:Please provide better details for the filenames


Thankyou very much for your response.

The description of file name 1.
For files type 1 it will not have duplicates why all the upload folders will deliver different names files.
1*ddmm.txt means 1 is type of report and its compulsory
----------- next is * means first 3 character of file name which can be VAT,RPT,SLR,STT, ....
----------- and day&month.
1VAT0701.txt, 1RPT0701.txt, 1SLR0701.txt

File type 2 will be dupicated that means from every upload this file TR(means transaction) files will be delivered in upload folder.
TRddmm.txt means TR common tag and next is day&month

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Recursively search in sub folders and move files

#4 Post by foxidrive » 06 Jan 2014 22:12

Why is it that you didn't give feedback in this thread? viewtopic.php?f=3&t=5225

Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Re: Recursively search in sub folders and move files

#5 Post by Danny » 06 Jan 2014 22:27

foxidrive wrote:Why is it that you didn't give feedback in this thread? viewtopic.php?f=3&t=5225


Its perfect, Infact i wanted to hide myself, you will say how many question this fellow is asking.

Its perfect and thats made me to asked this question, i have always got the answers from this forum

Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Re: Recursively search in sub folders and move files

#6 Post by Danny » 08 Jan 2014 06:18

Hi Foxidrive, Please help!

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Recursively search in sub folders and move files

#7 Post by foxidrive » 08 Jan 2014 06:35

When people help, they really do expect a simple 'thanks' and to find out if the code worked or not.
It's not too much to ask and isn't unreasonable.

It's unfortunate that in recent years a lot of people accept this free help and don't bother replying, unless they need some changes or have another problem.

Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Re: Recursively search in sub folders and move files

#8 Post by Danny » 08 Jan 2014 06:59

Hi,

My apologies, foxidrive i will not repeat this in future.

Post Reply