This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File Renaming while getting copied.  RSS feed

 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I need an approach for my requirement, any pointers will be helpful.

Requirement - I have a file (size of 20 gb) I will be copying it to a mapped drive, but while copying I have to keep my file name with an extension as ".wait" and then when it gets fully copied I have to rename it to the proper extension say ".exn".

There will be a large number of files coming in and I am looking for a approach which wont affect the performance.

P.S: The requirement is not LOCKING the file, I just have to rename it until i finish copying.

Thanks in advance.



... Happy Developing
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Please read this.


Hi Bear, sorry. read that but how to change the subject now : D
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robin John wrote:Hi Bear, sorry. read that but how to change the subject now : D


You don't see an Edit button on the post?

Anyway, I don't understand the question. I assume it's the target that these requirements refer to, i.e. the file you are copying the data to? If so, then just copy the data to a file whose name is "blabla.wait" and when you're finished copying, rename it appropriately.
 
Robin John
Ranch Hand
Posts: 281
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aaaah... got it.. now I know if you press edit on the comment box you can also change the subject... may be we should have one edit button beside the subject line... just an opinion : )

Okay for the question..

The problem is when I copy the file entirely and put it in that folder it will be picked up by another application and that will check if the extension is .exn and if not it will be purged. The application checks the folder for every 0.3 seconds if the file is modified or not and then picks it up.

so I thought of renaming the file just before the end of file is reached, can this be done ? and if I go for your approach will 0.3 seconds will be enough to rename the file after its copied "everytime".

I know this may sound obvious but just wanted to confirm.

Regards.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I must be misunderstanding your requirements. Now you seem to be saying that the receiving application will purge files whose extension isn't .exn, every 0.3 seconds. You can't copy a 20MB file anywhere in 0.3 seconds. So this doesn't make any sense to me.

And assuming that wasn't what you meant to say, I don't understand why you want to rename the file before you finish copying it. That just exposes you to the risk that the receiving application will do something with it before the copying is complete.

You can certainly rename a file in under 0.3 seconds but I don't understand why that's an issue at all. If the thing works the way I expect it does (as opposed to the way you're describing it), then the receiving application will see your renamed file within 0.3 seconds of your renaming it. Assuming it does its sweep every 0.3 seconds, that is.
 
Randi Randwa
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is an interesting problem. I may have come across it a time or two.

Facts:
1. When large files are copied, OS will create the node for that file before completing the copying and writing EOF. Other applications can see and read that file. They can not write, rename, move or delete that file.
2. In terms of speed, rename is faster than move. And move is faster than copy.
3. Rename CAN NOT occur until EOF is written, that is, until file is completed copying.
4. I am assuming the file in question and the application/scripts are all on a local system. FTP files have slightly different facts.

Is the question here:

How can I ensure that the receiving application does NOT see the file until it is completed copying ?



Randi
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!