create a log of files excluded using xcopy

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
pkearan
Posts: 4
Joined: 27 Aug 2012 22:59

create a log of files excluded using xcopy

#1 Post by pkearan » 27 Aug 2012 23:02

I want to have a log of only the files which xcopy excluded while copying the directories which I specified in the batch script. eg. my script is doing this

xcopy "first folder name" "second folder name" /s /i /Y /f /exclude:excludefiles.txt

I want to have a log of the files which were excluded and not copied into second folder.

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

Re: create a log of files excluded using xcopy

#2 Post by foxidrive » 28 Aug 2012 02:15

We'd have to replicate the scenario - can you paste and copy the screen output where it excludes files, and a few lines above and below?

pkearan
Posts: 4
Joined: 27 Aug 2012 22:59

Re: create a log of files excluded using xcopy

#3 Post by pkearan » 28 Aug 2012 23:35

On the screen it just shows the paths of the files copied no mention of the excluded files.

Applying Patch for "D:\Release\Client"
D:\Release\Patch_Control\PATCH_20120827\Client Release\BusinessObjects.dll -> D:\Release\Client\BusinessObjects.dll
D:\Release\Patch_Control\PATCH_20120827\Client Release\BusinessObjects.pdb -> D:\Release\Client\BusinessObjects.pdb
D:\Release\Patch_Control\PATCH_20120827\Client Release\CommonDataCache.dll -> D:\Release\Client\CommonDataCache.dll
D:\Release\Patch_Control\PATCH_20120827\Client Release\CommonDataCache.pdb -> D:\Release\Client\CommonDataCache.pdb
4 File(s) copied
Patch file:"D:\Release\Patch_Control\PATCH_20120827\Client Release" applied successfully

the first and last line are echoed in the script others are the result of xcopy.
in the above the client release folder also contains the files which have been excluded such as .xml files.

the script actually copies the patch files to the actual release and the xml files are changed manually for different releases.
In short I am getting a log of files copied instead I want a log of files not copied so that I can easily do it manually and also I have a reference.

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

Re: create a log of files excluded using xcopy

#4 Post by foxidrive » 28 Aug 2012 23:44

Use your exclusions file to create a file list:

Assuming your exclusions file looks like this
*.xml
xyz*.avi

then this should create the exclusions list for you: (untested)


Code: Select all

@echo off
for /f "delims=" %%a in (exclusions.txt) do (
dir /b /s /a-d "%%a">>"skipped files.txt"
)

pkearan
Posts: 4
Joined: 27 Aug 2012 22:59

Re: create a log of files excluded using xcopy

#5 Post by pkearan » 29 Aug 2012 00:07

my exclusion files looks like

.xml
.config

no wildcard supported in xcopy
Also the batch file is running in a different location than the directories being copied so I think this line will not work

dir /b /s /a-d "%%a">>"skipped files.txt"

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

Re: create a log of files excluded using xcopy

#6 Post by foxidrive » 29 Aug 2012 01:20

Then you can use this line:


dir /b /s /a-d "c:\source\folder\*%%a">>"skipped files.txt"

pkearan
Posts: 4
Joined: 27 Aug 2012 22:59

Re: create a log of files excluded using xcopy

#7 Post by pkearan » 29 Aug 2012 02:07

I did this to solve the issue
(dir /b /s /a-d "%DownloadedPatchPath%\%fold%")|findstr /g:excludefiles.txt >>"%DownloadedPatchPath%\skipped.txt"

does it have any vulnerability

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

Re: create a log of files excluded using xcopy

#8 Post by foxidrive » 29 Aug 2012 03:26

No worries, you're welcome.

Ocalabob
Posts: 79
Joined: 24 Dec 2010 12:16
Location: Micanopy Florida

Re: create a log of files excluded using xcopy

#9 Post by Ocalabob » 29 Aug 2012 09:19

Greetings all!
Another solid solution by foxidrive! Thank you sir!

If I may, I would like to indulge the forum with my solution using
Robocopy.

Code: Select all

@echo Off
::Limited Testing using XP SR3 and ROBOCOPY Ver. XP010
::Part One. ROBOCOPY Files with some exclusions and create a log file.
ROBOCOPY c:\first_folder_name c:\second_folder_name /e /xf /ndl *.xml *.config *.jpg /v /log:skipped1.txt

::Part Two Clean up the log file created by ROBOCOPY to simulate
::a DIR listing.
type skipped1.txt | find "named">skipped2.txt
for /f "delims=" %%a in ('type "skipped2.txt"') do call :take_out %%a
del skipped?.txt
goto :eof
:take_out
setlocal
set line=%*
echo %line:~16,65%>>"skipped_files.txt"


Caveats and Notes:
1. XP and above is required for Robocopy. If using XP then the
Resources Kit will have needed to have been installed. My thanks
to Squashman regarding the Resource Kit information.
2. I excluded *.jpg files for my own testing.
3. I had to play around with the line "echo %line:~16,65%" to allow
for long path/file names. May need further adjustment by the user.
4. Sub folders of "c:\first_folder_name" will be copied and if
"c:\second_folder_name" does not exist it will be created.

Best wishes!

Post Reply