0

I am having trouble copying all .txt files from a folder(which has one sub_folder) into a different folder. I went through most of the existing threads and this is what I tried,

xcopy /s %logfolder%\*.txt  %monthlylogcopy%\
for /R %logfolder%  %f in (*.txt) do copy %f %monthylcopy%\

Result: In both these cases, only 1 .txt file is always copied from source to destination. There are over 20 .txt files in the folder and sub-folder.

NOTE: Used single '%' in 2) because I was running it in cmd.

PLease let me know what I am missing. Thank you in advance.

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • check answer [here](http://stackoverflow.com/questions/30335159/windows-cmd-batch-for-r-with-delayedexpansion), I think it should help you. – QuickFix May 11 '17 at 17:11
  • Do you want the said sub-folder to be copied to the destination also, or do you want only its contents to be copied? What are the contents of your variables? – aschipfl May 11 '17 at 23:25

1 Answers1

0

It looks like you forgot to add a backslash between %logfolder% and the file extension *.txt. The following command should work assuming that the variables actually contain valid paths:

xcopy /s "%logfolder%\*.txt" "%monthlylogcopy%\"
303
  • 2,417
  • 1
  • 11
  • 25
  • 1
    the "missing" backslash was actually there, but this site's formatting didn't show it. I properly formatted the code in the question. – Stephan May 11 '17 at 17:25
  • Could you add the following commands at the bottom of your script and update your question with the result that they output? `set logfolder`, `set monthlylogcopy`, and `dir "%logfolder%"` – 303 May 11 '17 at 17:46
  • @Stephan, treintje Thank you for the response. The below answer worked for me http://stackoverflow.com/a/21791974/7175940 – Venkatesh Kannan May 11 '17 at 18:43