Copy File Using Fso Vb6

I am trying to copy a file to another server using FSO.CopyFile but I get a permission error. I can copy the file with windows explorer without a problem but not.

Iggy Pop & Stiff Little Fingers. Edit the album Report an error. Split, 1982, Chrysalis Records. The Horse Song. Iggy pop discography completa download chrome.

I am using the following code in an attempt to copy a file from one folder to another, but I get the above referenced error. Any suggestions?

It will check to see if the file already exists in the destination folder, and if it does will check if the file is read-only. If the file is read-only it will change it to read-write, replace the file, and make it read-only again. Const DestinationFile = 'c: destfolder anyfile.txt' Const SourceFile = 'c: sourcefolder anyfile.txt' Set fso = CreateObject('Scripting.FileSystemObject') 'Check to see if the file already exists in the destination folder If fso.FileExists(DestinationFile) Then 'Check to see if the file is read-only If Not fso.GetFile(DestinationFile).Attributes And 1 Then 'The file exists and is not read-only.

Safe to replace the file. Fso.CopyFile SourceFile, 'C: destfolder ', True Else 'The file exists and is read-only. 'Remove the read-only attribute fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1 'Replace the file fso.CopyFile SourceFile, 'C: destfolder ', True 'Reapply the read-only attribute fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1 End If Else 'The file does not exist in the destination folder. Safe to copy file to this folder. Fso.CopyFile SourceFile, 'C: destfolder ', True End If Set fso = Nothing. Here's an answer, based on (and I think an improvement on) Tester101's answer, expressed as a subroutine, with the CopyFile line once instead of three times, and prepared to handle changing the file name as the copy is made (no hard-coded destination directory). I also found I had to delete the target file before copying to get this to work, but that might be a Windows 7 thing.

The WScript.Echo statements are because I didn't have a debugger and can of course be removed if desired. Sub CopyFile(SourceFile, DestinationFile) Set fso = CreateObject('Scripting.FileSystemObject') 'Check to see if the file already exists in the destination folder Dim wasReadOnly wasReadOnly = False If fso.FileExists(DestinationFile) Then 'Check to see if the file is read-only If fso.GetFile(DestinationFile).Attributes And 1 Then 'The file exists and is read-only. WScript.Echo 'Removing the read-only attribute' 'Remove the read-only attribute fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1 wasReadOnly = True End If WScript.Echo 'Deleting the file' fso.DeleteFile DestinationFile, True End If 'Copy the file WScript.Echo 'Copying ' & SourceFile & ' to ' & DestinationFile fso.CopyFile SourceFile, DestinationFile, True If wasReadOnly Then 'Reapply the read-only attribute fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1 End If Set fso = Nothing End Sub. Just posted my finished code for a similar project. It copies files of certain extensions in my code its pdf tif and tiff you can change them to whatever you want copied or delete the if statements if you only need 1 or 2 types. When a file is created or modified it gets the archive attribute this code also looks for that attribute and only copies it if it exists and then removes it after its copied so you dont copy unneeded files.

It also has a log setup in it so that you will see a log of what time and day evetrything was transfered from the last time you ran the script. Hope it helps!

    Search