1.

Solve : Suppressing XCOPY Message?

Answer»

Hi,

I would like to suppress the following message displayed by XCOPY command.

Does destination specify a file name
or directory name on the target
(F = file, D = directory)?

I tried giving /I in the command line OPTION. But it didnt work.

However i would like to enter 'F' for the above message.

Is there anyway i can hardcode 'F' in the batch pgm, so that it uses for the message?

Thanks.
You should be able to redirect input from a file using '<'

Are you renaming the file as you copy it? There is probably a better way to do what you are trying to do. Post the whole XCOPY command that you are using and we can probably come up with an alternate solution, like the syntax of the XCOPY command or another way of copying the file.hi,

Below is the XCOPY syntax i am using.

for /f "delims=" %%a in ('dir/b/a-d D:\Source') do (
if exist "D:\Destination\%%a" (
xcopy "D:\Destination\%%a" "D:\%1_Backup\%%a" /S/E/H/R/Y/F/Q/I
)
)I don't know the structure of your D:\Destination directory, but since the DIR in your FOR loop is not using /S and is also excluding DIRECTORIES, I assume it is a flat directory? If that is the case, you don't need the /S and /E (of which /S would be redundant anyway) and also the /F and /Q switches are opposites (and both cosmetic).

If you aren't copying any hidden, system or write-protected files, then you COULD probably replace your XCOPY line with:
Code: [Select]copy "D:\Destination\%%a" "D:\%1_Backup\%%a" /YIf you are copying hidden files, you may need to precede your copy with
attrib -r -h -s "D:\Destination\%%a"
or if copying write protected files, you may need to precede your copy with
attrib -r "D:\%1_Backup\%%a"Quote

xcopy "D:\Destination\%%a" "D:\%1_Backup\%%a"

Removing the destination filename might suppress the message, it's not needed in this case.

Quote from: Dusty on February 19, 2009, 12:17:33 AM
Removing the destination filename might suppress the message, it's not needed in this case.

Yes, that does seem more simple. GOOD solution!Hi All,

Thanks for the valuable input.

I should have excluded the -d in my DIR command in the FOR Loop as it is not a Flat Directory.

Below is the Problem:
I have two folders A & B. I want to search for a particular file from Folder A in Folder B, if is present, copy that file from Folder B to Folder C. If it is not Present copy that file from Folder A to Folder D.

Solution:

I have written the below code to search and copy the files. However i'm unable to suppress the XCOPY message:

@ echo off

if exist d:\%1_Backup del/Q d:\%1_Backup
if exist d:\%1_Del del/Q d:\%1_Del

mkdir d:\%1_Backup
mkdir d:\%1_Del


for /f "delims=" %%a in ('dir/b/a D:\Source') do (
if exist "D:\Destination\%%a" (
xcopy "D:\Destination\%%a" "D:\%1_Backup\%%a" /S/E/H/R/Y/F/Q/I
>%2
)
)

for /f "delims=" %%a in ('dir/b/a D:\Source') do (
if not exist "D:\Destination\%%a" (
xcopy "D:\source\%%a" "D:\%1_Del\%%a" /S/E/H/R/Y/F/Q/I
>%2
)
)

Pause

Below is my directory structure:

Source Destination
Compile Compile
FTP FTP
ISO ISO
NSR Vehicle
Paint WRC
Painting Tips ABC [Folder]
POLK abdc
POLK-jan09
Vehicle
WRC
ABC [Folder]
abdc
extra

In the above directory structure, the code is not copying the contents of the folder ABC correctly. (i.e) it is copying only the folder ABC and not the contents of the folder abdc and extra.

Thanks for your help.

Quote from: ponnisundar on February 19, 2009, 10:30:22 PM
I have two folders A & B. I want to search for a particular file from Folder A in Folder B, if is present, copy that file from Folder B to Folder C. If it is not Present copy that file from Folder A to Folder D.

I am confused. You say you have 2 folders, but you are referring to Folder A, Folder B, Folder C and Folder D which is actually 4 folders.Quote from: ponnisundar
I have written the below code to search and copy the files. However i'm unable to suppress the XCOPY message:

Did you not read or understand this?
Quote from: Dusty on February 19, 2009, 12:17:33 AM
Quote
xcopy "D:\Destination\%%a" "D:\%1_Backup\%%a"

Removing the destination filename might suppress the message, it's not needed in this case.

Quote from: ponnisundar
xcopy "D:\Destination\%%a" "D:\%1_Backup\%%a" /S/E/H/R/Y/F/Q/I
>%2

xcopy "D:\source\%%a" "D:\%1_Del\%%a" /S/E/H/R/Y/F/Q/I

Remove the %%a variables (only those which are emboldened and underlined) which contain the output filenames, they are not required in the Xcopy commands. This should suppress the Xcopy message.

Quote from: ponnisundar
In the above directory structure, the code is not copying the contents of the folder ABC correctly. (i.e) it is copying only the folder ABC and not the contents of the folder abdc and extra.

Quote from: ponnisundar
for /f "delims=" %%a in ('dir/b/a D:\Source') do (

The Dir command in For extracts only the names of files which are ready to archive in the Source directory, not those in subdirectories. You must include the /S switch to extract those but that will extract all the qualifying filenames in all subdirectories. Is that what you want or do you want to extract filenames only from ABC, ABCD and EXTRA. If the latter then the Dir command path should be D:\ABC\ and the /S switch must be present.

I'm also confused as to your directory structure, maybe Source is a directory and all the rest are subdirectories of Source?


Input
Folder A - Source
Folder B - Destination

Output

Folder C - _Backup
Folder D - _Del

I Just want the code to work on the folders Source and Destination and copy the contents to _Backup & _Del based on the following rule

Folder C: Contains all files from B that exist in A.
Folder D: Contain All files from A that do not exist in B.

Thanks.



Hi,

I saw your input for supressing the XCOPY message. I used that and it worked. Thanks a lot for that. But i missed removing that while posting in the forum.

But the problem i face now is the XCOPY is not copying the contents of folders inside the Source & Destination. Instead it is just copying the folder alone.

Corrected Code:

Code: [Select]@ echo off

if exist d:\%1_Backup del/Q d:\%1_Backup
if exist d:\%1_Del del/Q d:\%1_Del

mkdir d:\%1_Backup
mkdir d:\%1_Del


for /f "delims=" %%a in ('dir/b/a D:\Source') do (
if exist "D:\Destination\%%a" (
xcopy "D:\Destination\%%a" "D:\%1_Backup\" /S/E/H/R/Y/F/Q/I
)
)

for /f "delims=" %%a in ('dir/b/a D:\Source') do (
if not exist "D:\Destination\%%a" (
xcopy "D:\source\%%a" "D:\%1_Del\" /S/E/H/R/Y/F/Q/I
)
)

Pause
Thanks.Read the bottom part of my reply #8


Discussion

No Comment Found