Click here to Skip to main content
13,865,393 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a batch script which first copies file from one location to other folder and then creates a list of name of the files in a text file:

Below Code:


dir /b \\CDFS23001\\SOURCE\TGT\*ACCOUNTS*.xml > \\CDFS23001\\SOURCE\TGT\List_Accounts.txt

First copy command copies file from ORG folder to TGT folder and then a list of filename is created.

Sometimes the List_Accounts.txt doesnt have any name inspite of accounts file being present in ORG location.

Is it possible before the file(s) is (are) completely completely copied to TGT (destination) folder by COPY command the second command dir /b gets executed ?

If this is happening what can I do to have some wait time between these two commands ?

Please suggest

What I have tried:

I think Timeout 60 will create a time gap of 60 seconds, but in case if more time is required to copy files then it might fail too. The size of the files is never fixed.
Updated 25-Jun-18 5:31am
Richard Deeming 26-Jun-18 11:39am
Are any of the files hidden? Try adding the /a flag to your dir call.
dir /a /b \\CDFS23001\\SOURCE\TGT\*ACCOUNTS*.xml > \\CDFS23001\\SOURCE\TGT\List_Accounts.txt
Aditya_ETL 26-Jun-18 11:49am
No, there are no hidden files, I think when the file size is around 20 MB Then before the copy command completely copies the file to the destination, dir command gets executed and geneartes the blank file list. But I am not sure if this is actually happening.
Is there any way to make sure first the file gets copied completely then only dir should execute ?
Richard Deeming 26-Jun-18 11:55am
As Dave said, the copy command doesn't return until the copy operation has finished.

Could the files be zero length? copy won't copy those - you'd need to use xcopy instead.

copy | Microsoft Docs[^]

If you want to try pausing between the operations, just in case there's something odd with the hardware, then you can use the timeout command[^].

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

It's not a timing problem.

It's a spelling problem. Look at your "ACCOUNTS" on one line and "ACCOUNT" on the next.
Aditya_ETL 25-Jun-18 10:31am
Hi Dave, it was not spelling mistake, typo error and missed a letter.
Can you suggest a solution
Dave Kreskowiak 25-Jun-18 10:38am
OK, you updated that in the question, but this still is not a timing problem.

The COPY command in the first line is a "blocking call". That means the next line will not execute until the copy command has COMPLETELY copied all files.

Do any of these filenames have spaces in them?

Give examples of the filenames you're dealing with.
Aditya_ETL 25-Jun-18 10:48am
Example of file: Netsol_ACCOUNTS_20180215.xml
Dave Kreskowiak 25-Jun-18 12:05pm
OK, given what you've posted, there is nothing wrong. The commands will work and will output the list of files to the text file PROVIDED they are running under an account that has appropriate access to the shares and folders in question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190214.1 | Last Updated 25 Jun 2018
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100