0

I have a folder MyFolder and it contains 3 sub-folders say A,B and C.

I want to copy those sub-folders which are modified today.

The command for /D %%A in ("D:\MyFolder*") do ( echo **%%~fA )** provides me all 3 sub-folders, now I am calling another loop and passing %%~fA(which is current folder in loop) to get to know is there any modifications made in this folder or not. But I am getting echo off.

  set LocalFolder=D:\Backup\1

    for /D %%A in ("D:\MyFolder\*") do (  
     echo %%~fA
    for /F %%N in ('forfiles /S /P "%%~fA" /M "*" /D +0 /C "cmd /C if @isdir==FALSE echo _" ^| find /C "_"') do set "NUMBER=%%N"
    echo %NUMBER%        
    if %%N GTR 0 xcopy "%%~fA\*.*" "%LocalFolder%\" /s/e/k/f/c        
     )
mandeep
  • 21
  • 1
  • 5
  • 1
    As I told you [yesterday](https://stackoverflow.com/questions/49448609/how-to-get-todays-modified-folders-in-a-directory-using-batch-file#comment85985392_49448609): you need [delayed expansion](http://ss64.com/nt/delayedexpansion.html) for variable `NUMBER`!! However, you do not need the `echo` command line anyway, so just remove it. Copying should work as is... – aschipfl Mar 27 '18 at 10:03
  • 1
    mandeep,given that you have posted several similar questions recently, and without wishing to be rude, could you please explain the whole task you're trying to perform, so that it prevents further unnecessary similar questions moving forward. – Compo Mar 27 '18 at 10:03
  • Instead of querying the files in the folders you could also simply check the modification dates of the folders in case you just want to know whether new files have been added (or some have been deleted). However, this does not reflect modification of files... – aschipfl Mar 27 '18 at 10:07
  • can you pls write the answer @aschipfl as I used delayed expansion as well but didn't get work for me... – mandeep Mar 27 '18 at 10:17
  • This one is the complete question @Compo......, is it unclear to you....? – mandeep Mar 27 '18 at 10:20
  • and if you have no answer then downvoting some one does not make you cool .... – mandeep Mar 27 '18 at 10:22
  • @mandeep, you currently have no way of knowing who downvoted you, but to help you narrow it down, **it wasn't me**! Your question seems odd in that you talk about one level, then perform a recursive search. Is your intention to back up, any top level directory, which contains any file which has been modified today? – Compo Mar 27 '18 at 10:28
  • i didn't mention your name @Compo, pl check my note.... – mandeep Mar 27 '18 at 10:30
  • and this is the requirement @Compo, what can I do ... – mandeep Mar 27 '18 at 10:31
  • may be my sentence which started with "and if you" made you feel that it was for you...but really it wasn't for you at all, it was for one who downvoted me without a good reason.. – mandeep Mar 27 '18 at 10:34
  • @mandeep, perhaps the question and intent is still unclear and perhaps that's why you were downvoted. _On that subject, if you'd care to refer back, I didn't suggest that you were singling me out as having downvoted you, just provided you with some help in narrowing down the list of members who may have done so!_ – Compo Mar 27 '18 at 11:03
  • thanks @Compo, yes I want to copy sub-directories if they are modified today.. where "D:\MyFolder\" is the main directory.. i don't know what is missing and why its saying echo is off......... – mandeep Mar 27 '18 at 11:06
  • I'll post an answer and retract my down-vote once you [edit] your question and precisely describe the intend of your script. At the moment this question is totally unclear and incomplete. I know about [your other similar question](https://stackoverflow.com/q/49448609) since I reacted on it yesterday, but other users don't, so they cannot understand what this is all about. Or perhaps even consider to delete this question and update the other question instead... – aschipfl Mar 27 '18 at 11:22
  • By the way: [yesterday](https://stackoverflow.com/questions/49448609/how-to-get-todays-modified-folders-in-a-directory-using-batch-file#comment85984931_49448609) I also told you that the `if %%N gtr 0` command line must be placed in the inner `for` loop; otherwise the reference `%%N` does not exist... – aschipfl Mar 27 '18 at 11:24
  • I am totally new in batch file, can you pl post an answer... – mandeep Mar 27 '18 at 11:27

0 Answers0