Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

COPY \\CDFS23001\\SOURCE\ORG\*ACCOUNTS*.xml \\CDFS23001\\SOURCE\TGT\

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.
Posted
Updated 25-Jun-18 4:31am
v2
Comments
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

It's not a timing problem.

It's a spelling problem. Look at your "ACCOUNTS" on one line and "ACCOUNT" on the next.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900