Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Moving Files and creating copies

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nils Titley - 29 Mar 2008 14:22 GMT
FSO.MoveFile

With FSO.MoveFile, can you move the files and if they exist write them with
a new name.  If not how can I do that?

Thanks
JLGWhiz - 29 Mar 2008 14:45 GMT
I would think that using SaveAs with the full path would allow you to move
and rename the files in one fell swoop.

> FSO.MoveFile
>
> With FSO.MoveFile, can you move the files and if they exist write them with
> a new name.  If not how can I do that?
>
> Thanks
Mark Ivey - 29 Mar 2008 15:54 GMT
I would recommend using some addition to the filename. I typically use
something extra like date and time information added to the original
filename to avoid overwriting previous versions of the same file.

If you need some examples, let me know.

Mark

> FSO.MoveFile
>
[quoted text clipped - 3 lines]
>
> Thanks
Nils Titley - 29 Mar 2008 16:12 GMT
Let me provide additional information.

The macro will be used by all sorts of people.  I want to make it easy for
them.  There is a data folder and an archive folder.  The macro process any
file that sits in the data folder.  After each file has been processed, a
report is generated and written to the report folder that is dated and timeed
stamped.  

I want to move all of the data files to the archive  folder.  I can do that
now.  But the person asking me to help create the macro is concerned that
there might be the same files in the archive folder.  I don't think that will
happen but in case, I want to move the files and if the file already exist in
the archive folder, I would like to rename it to some thing like "filename
copy".

Does that help?

Thanks

> FSO.MoveFile
>
> With FSO.MoveFile, can you move the files and if they exist write them with
> a new name.  If not how can I do that?
>
> Thanks
Ron de Bruin - 29 Mar 2008 19:48 GMT
See also
http://www.rondebruin.nl/folder.htm

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Let me provide additional information.
>
[quoted text clipped - 21 lines]
>>
>> Thanks
Nils Titley - 30 Mar 2008 11:34 GMT
Ron,

Thanks for the suggestion but I could not find in your pages what I need to
do.

> See also
> http://www.rondebruin.nl/folder.htm
[quoted text clipped - 24 lines]
> >>
> >> Thanks
urkec - 30 Mar 2008 15:24 GMT
You could try copying files individually using FSO File.Move, and if it
returns 'file exists' error (58), use a different name. Something like this
(please be careful, this is not tested):

strSourceFolder = "c:\source\"
strDestFolder = "d:\destination\"

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objSourceFolder = objFso.GetFolder(strSourceFolder)

For Each objFile In objSourceFolder.Files

  On Error Resume Next

  objFile.Move strDestFolder

  If Err.Number = 58 Then
  i = 1
     Do While Err.Number <> 0

        Err.Clear
       
        objFile.Move strDestFolder & "Copy Of " & _
        objFso.GetBaseName(objFile) & _
        " (" & i & ")" & "." & _
        objFso.GetExtensionName(objFile.Path)
       
        i = i + 1
     
     Loop
  Else
     Debug.Print Err.Number, Err.Description
  End If

  On Error GoTo 0

Next

Signature

urkec

> Ron,
>
[quoted text clipped - 29 lines]
> > >>
> > >> Thanks
Nils Titley - 31 Mar 2008 16:25 GMT
Urkec,

Your code worked perfectly.  Thanks for helping me.

> You could try copying files individually using FSO File.Move, and if it
> returns 'file exists' error (58), use a different name. Something like this
[quoted text clipped - 67 lines]
> > > >>
> > > >> Thanks
Ron de Bruin - 30 Mar 2008 21:34 GMT
Hi Nils

Checking if each file exist in a loop is the only way.

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Ron,
>
[quoted text clipped - 29 lines]
>> >>
>> >> Thanks
Nils Titley - 31 Mar 2008 12:00 GMT
Thanks for the help.  I will give it a try.  I dont' think it is necessary to
check if they exist but better to check than to get an error and have the
move fail.  I don't think it is necessary to check because I don't think
there will be duplicate files.

> Ron,
>
[quoted text clipped - 29 lines]
> > >>
> > >> Thanks
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.