-4

here is my command

Exclude function is not working with xcopy

@Echo Off 
set source=C:\Users\garang\Documents\input_files2\Advisory_Rate
set destination=C:\Users\garang\Documents\input_files2\Advisory_Rate\Archive
xcopy "C:\Users\garang\Documents\input_files2\Advisory_Rate" "C:\Users\garang\Documents\input_files2\Advisory_Rate\Archive" /S /C /Y /EXCLUDE:"C:\Users\garang\Documents\input_files2\Advisory_Rate\Advisory Rate mapping.xlsx"

error:

C:\Users\garang\Documents\input_files2\Advisory_Rate>movefiles 
Can't read file: "C:\Users\garang\Documents\input_files2\Advisory_Rate\Advisory Rate mapping.xlsx" 
0 File(s) copied 
C:\Users\garang\Documents\input_files2\Advisory_Rate> 

Here is the reference question, I have abandoned for this question.

Compo
  • 36,585
  • 5
  • 27
  • 39
  • 1
    What's the point of providing code and errors in comments? Please post them in the question by [edit]ing your post and [format](https://stackoverflow.com/help/formatting) them properly! Make sure the code is a [mcve]! Furthermore, read the [tour] and learn [ask] here! – aschipfl Jun 19 '18 at 14:14
  • what makes you think, `xcopy` can read `XLSX` files? Use a plain text file instead. (`.csv` would be ok, because `.csv` *is* plain text) – Stephan Jun 19 '18 at 14:58
  • understand but the requirement is to move all .xlsx files to archive folder except 2 excel files – Rupesh Shelar Jun 19 '18 at 15:03
  • @RupeshShelar, did you read the help file? It is pretty clear how the exclude option works. You need to put your excludes inside a text file. – Squashman Jun 19 '18 at 15:06
  • I have added a [reference footnote](https://stackoverflow.com/q/50796886/6738015) to your question, to prevent people from repeating the advice I've already provided you. – Compo Jun 19 '18 at 15:09
  • @RupeshShelar, open a new text file. On line `1`, put the filename of the first `.xlsx` file you don't want to copy; On line `2` put the filename of the other `.xlsx` file you don't want to copy; Save the file as `ExcludeUs.txt`. Put `ExcludeUs.txt` in the same location as your batch file/current directory, change the `XCopy` command to `XCopy "%source%" "%destination%" /S /C /Y /EXCLUDE:ExcludeUs.txt`; and run the batch file! – Compo Jun 19 '18 at 15:32
  • 1
    As others already pointed out, `/EXCLUDE` option expects a text file that contains (partial) paths to exclude. The path to the text file must not contain white-spaces or special characters and must not be put in quotes; otherwise it fails. See [this post](https://stackoverflow.com/a/42399461) to learn more... – aschipfl Jun 19 '18 at 15:39
  • working ...@Echo Off set source=C:\Users\garang\Documents\input_files2\Advisory_Rate set destination=C:\Users\garang\Documents\input_files2\Advisory_Rate\Archi ROBOCOPY C:\Users\garang\Documents\input_files2\Advisory_Rate C:\Users\garang\Documents\input_files2\Advisory_Rate\Archive\ /XF C:\Users\garang\Documents\input_files2\Advisory_Rate\Quick_OPU_listing.xlsx – Rupesh Shelar Jun 19 '18 at 16:17
  • i wanted to move the files and exclude the two files command instead of robocopy – Rupesh Shelar Jun 19 '18 at 16:30
  • 1
    @RupeshShelar, please do not put that much code into a comment. You should edit your question with that information. – Squashman Jun 21 '18 at 04:58

1 Answers1

0

RoboCopy can move files and directories too!!

If you have just that one directory named Archive in that particular tree you could probably use this:

@CD /D "%UserProfile%\Documents\input_files2\Advisory_Rate" 2>Nul || Exit /B
@RoboCopy . Archive /S /Move /XD "Archive" /XF "Advisory Rate mapping.xlsx" "Quick_OPU_listing.xlsx" 2>Nul
Compo
  • 36,585
  • 5
  • 27
  • 39
  • Hi Compo, i fixed all this only thing is i wanted to exclude this Advisory_Rate folder from your earlier query...please help me with last step+++++++++++++++++++++++++@Echo Off Set "dirSrc=C:\Users\garang\Documents\input_files" Set "dirDst=Archive" Set "extSrc=*.xlsx" CD /D "%dirSrc%" 2>Nul || Exit /B For /D %%A In (*) Do (PushD "%%A" For /F "Skip=1 Delims=" %%B In ( 'Dir /B/A-D-H-L-S/O-D/TW "%extSrc%" 2^>Nul') Do ( If Not Exist "%dirDst%\" MD "%dirDst%" Move /Y "%%B" "%dirDst%">Nul 2>&1) PopD) – Rupesh Shelar Jun 21 '18 at 07:31
  • @RupeshShelar, my first comment in the reference question answered the your initial query on skipping a directory, as did the advice both here and in that reference topic on the usage of `XCopy`'s `/Exclude` with directory names and `RoboCopy`'s `/XD` option. This site is not a free code request service, an interactive search facility or a one to one private tutor service. Providing answers does not contract us into lifetime support with the OP. Please read all of the advice, learn how to use all of the commands, and practice, until you achieve your intended result. – Compo Jun 21 '18 at 15:13
  • i tried this command at end of the query but not taking /XD C:\Users\garang\Documents\input_files\Advisory_rate....unable to exclude the folder from your earlier query – Rupesh Shelar Jun 21 '18 at 15:48
  • @RupeshShelar, please try to look at the problem logically; you cannot exclude `Advisory_Rate`, if it is also the source directory! – Compo Jun 21 '18 at 16:33
  • but for Advisory_Rate we want /XF "Advisory Rate mapping.xlsx" "Quick_OPU_listing.xlsx" we want only these two files to be there and not move – Rupesh Shelar Jun 21 '18 at 16:50