CopyFile (from the French Team)

Speak your mind

CopyFile (from the French Team)

Postby scottw on Tue Oct 10, 2006 6:43 pm

I am using copyfile and it works fine but how can I make it overwrite a file that already exists. It works fine for copying to a destination that does not have that same filename but I want to use it to update a file that already exeists.

Any way???
scottw
 
Posts: 774
Joined: Mon Feb 06, 2006 4:21 pm
Location: Glen Burnie, Maryland

Postby scottw on Thu Oct 19, 2006 12:23 pm

Bump, anyone???
scottw
 
Posts: 774
Joined: Mon Feb 06, 2006 4:21 pm
Location: Glen Burnie, Maryland

Postby dgemily on Thu Oct 19, 2006 4:32 pm

you need to modify the script, but I'm not able to do it... sorry.... maybe someone else ....?
dgemily
 
Posts: 793
Joined: Thu May 13, 2004 6:24 am
Location: Paris, France

Postby scottw on Thu Oct 19, 2006 6:16 pm

Thanks dgemily. I would do it but I can't quite understand where, I tried a few things but none of them work.

Can anyone else help???

Here is the script :http://www.france.xlobby.com/forum/ptrinchi/Scripts/CopyFile.zip
scottw
 
Posts: 774
Joined: Mon Feb 06, 2006 4:21 pm
Location: Glen Burnie, Maryland

Postby cmhardwick on Thu Oct 19, 2006 7:00 pm

Looking at the script, the actual copy occurs in this section
-----------
' ****** Copy the file **************************
if (OK = True)
If (Folder.ToLower() = "folder") Then
FolderName = Dest & System.IO.Path.GetFileNameWithoutExtension(fichiers(compteur)) & "\"
System.IO.Directory.CreateDirectory(FolderName)
End If
If (Folder.ToLower() = "date") Then
FolderName = Dest & System.DateTime.Now.Year.ToString() & "-" & System.DateTime.Now.Month.ToString() & "-" & System.DateTime.Now.Day.ToString() & "\"
System.IO.Directory.CreateDirectory(FolderName)
end if
System.IO.File.Copy(fichiers(compteur), FolderName & System.IO.Path.GetFileName(fichiers(compteur)))
NbCopie = NbCopie + 1
end if
Next
-------------
Now, in DOS, you can use the switch /y at the end of the copy command to force an overwrite. Not sure if this will work here, but you might try this ....

Replace the System.IO.File.Copy, etc with this
System.IO.File.Copy(fichiers(compteur), FolderName & System.IO.Path.GetFileName(fichiers(compteur))" /y")

You might have to play with the quotes, etc.

I don't have any way of testing, and not sure if this script will actually use the same parameters as the actual DOS copy command, but worth a shot.

:?
cmhardwick
 
Posts: 508
Joined: Fri Jul 14, 2006 6:07 pm
Location: Tennessee

Postby scottw on Thu Oct 19, 2006 7:01 pm

Thanks alot.
I will try and let you know!!!!
scottw
 
Posts: 774
Joined: Mon Feb 06, 2006 4:21 pm
Location: Glen Burnie, Maryland

Postby cmhardwick on Thu Oct 19, 2006 7:06 pm

Be warned, this will ALWAYS overwrite, so be carefull with your parameters.

This would be great for something that's being discussed in another thread (changing the splash screen for TheaterTek to show the cover of the movie being started) :wink:
cmhardwick
 
Posts: 508
Joined: Fri Jul 14, 2006 6:07 pm
Location: Tennessee

Postby m_ski on Fri Oct 20, 2006 12:12 pm

Taken from MSDN... http://msdn2.microsoft.com/en-us/library/9706cfs5.aspx

.NET Framework Class Library
File.Copy Method (String, String, Boolean)
Copies an existing file to a new file. Overwriting a file of the same name is allowed.

Parameters
sourceFileName
The file to copy.

destFileName
The name of the destination file. This cannot be a directory.

overwrite
true if the destination file can be overwritten; otherwise, false.


So you will need to use...
Code: Select all
System.IO.File.Copy(fichiers(compteur), FolderName & System.IO.Path.GetFileName(fichiers(compteur)), true)


The warning from cmhardwick still applies - It will ALWAYS overwrite.
m_ski
 
Posts: 204
Joined: Wed Dec 08, 2004 7:57 am
Location: Kent, United Kingdom

Postby scottw on Fri Oct 20, 2006 12:56 pm

Thanks so much guys!!!!

The , true worked fine.

The overwriting is not a problem, that's what I need it to do. I have my Ant movie DB located on my web server (a different machine) that I can FTP the most recent file to from anywhere. Then I just copy the file from the WebServer to my Xlobby machine so the most recent copy will always be on the webserver, so overwriting is what I want.


Thanks again everyone for your help!!!
scottw
 
Posts: 774
Joined: Mon Feb 06, 2006 4:21 pm
Location: Glen Burnie, Maryland