How create BATH file for file copy

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
oleg2206
Posts: 3
Joined: 31 Oct 2011 15:25

How create BATH file for file copy

#1 Post by oleg2206 » 31 Oct 2011 15:36

Hello. I new here. You have nice forum.
I need to create bath file for copy file, that will be created by my program, from original folder to backup folder.
I can't to know the name of the file and I need to execute this BATCH in time of creation (for this i have parameter in my program, with execute any executable files).
My development gay give me this :
copy %1 C:\Backup_folder
but it"s not work.
What they forget to say to me?
Please help me
Oleg

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How create BATH file for file copy

#2 Post by aGerman » 31 Oct 2011 16:02

It's hard to understand what you're looking for.
OK, what I understood so far:
- a program creates a file
- you need to copy the file into "C:\Backup_folder"

Question:
Do you know the name of the file?
  • YES
    Can you call a batch file with that name as parameter?

    Code: Select all

    copy %1 C:\Backup_folder\
  • NO
    How could you find out the name?

Regards
aGerman

oleg2206
Posts: 3
Joined: 31 Oct 2011 15:25

Re: How create BATH file for file copy

#3 Post by oleg2206 » 31 Oct 2011 16:54

Hi.
You understand correctly.
System generate file, but i can not know the name of the file. The name depend on other parameters.
Yes, I can call the bath file, but I have possibility to put only the path to batch file. I don't know how I can declare the parameter.
Or you mean to call the batch file which have a name as a parameter?

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How create BATH file for file copy

#4 Post by aGerman » 31 Oct 2011 18:03

Hmm. If you don't know the file name you have to define the rules how to find the right file. For Example:
-Is it always the same folder where the file is generated?
-Has it always the same file extension? (.txt or .csv or .xml or ...)
-Is there only one file with that extension in the folder?

What else is suitable to find the file? I need your collaboration because I don't have all the background information.

Regards
aGerman

oleg2206
Posts: 3
Joined: 31 Oct 2011 15:25

Re: How create BATH file for file copy

#5 Post by oleg2206 » 31 Oct 2011 22:28

First of all, thank you about your responds.
Second, I know the folder and sometimes I have something constant in the name or in the extension. Also, this folder is always empty, because other program take this file(s), but i can't based on this because it's always delay - I mean, my program generate file every 5 minutes, and other program take files every 2 minutes.
So basic constant rule : folder name, and sometimes extension.
Also, the OS in the machine is Win Server 2008 32 bit.
Based on this, what your suggestions?
Best Regards
Oleg

aGerman
Expert
Posts: 4705
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How create BATH file for file copy

#6 Post by aGerman » 01 Nov 2011 14:43

oleg2206 wrote:I mean, my program generate file every 5 minutes, and other program take files every 2 minutes.

You should think about it. In the worst case your program generates the file and at the same time the other program removes it. How should the batch copy a nonexisting file? I'm afraid it's impossible to make sure that it would always work.

To copy each existing file in a folder you could use the asterisk

Code: Select all

copy "C:\where\the\files\are\generated\*" "C:\Backup_folder\"


Regards
aGerman

Post Reply