copy file to folder

copy file to folder

Anonymous
Not applicable
693 Views
3 Replies
Message 1 of 4

copy file to folder

Anonymous
Not applicable

Hi all

 

I am looking for some help to copy a file to a folder.

 

all the copy methods I have seen state I need to know the path and filename..

 

I'd simply like to do something like the following and only specify the folder I am copying the file to and not the filename..

 

copy c:\temp.txt c:\temp2

 

is it possible folks? 

 

thanks

 

0 Likes
694 Views
3 Replies
Replies (3)
Message 2 of 4

clutsa
Collaborator
Collaborator

Like this?

Dim app As Inventor.Application = ThisApplication
Dim doc As Document = app.ActiveDocument
doc.SaveAs("C:\temp\" & doc.DisplayName,True)

This will use the same name as the current file but put it in a different drive loc.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 4

Anonymous
Not applicable

hi @clutsa

 

I'm actually trying to move/copy some pdf files from one folder to another.

To know which pdf files to move, I use the active document that the rule is  ran from and then I use the first 13 characters of the inventor document filename as a string to search for ( and then use a wildcard after that)

 

e.g the files may be called

(inventor file = 1234567890abc-something.idw)

 

(pdf files to move folders)

1234567890abc-some other text.pdf

1234567890abc-some other text 2.pdf

etc... etc.

 

so I can use the following to trim the inventor filename and then -hopefully- use that (plus a wildcard ) to search the dir for pdf files...

 

Dim oName As String

oName = Left(oDoc.DisplayName, 13

 

but how do I move/copy all instances of pdf files  who have the same first 13 characters as the active inventor doc?

 

thanks for any help

 

 

0 Likes
Message 4 of 4

clutsa
Collaborator
Collaborator

This should get you started. This is VBA code so you need to set a reference to "Microsoft Scripting Runtime".

Sub CopyOtherFiles()
Dim app As Application
Dim doc As Document

Set app = ThisApplication
Set doc = app.ActiveDocument
Set FSO = New Scripting.FileSystemObject
DocPath = Left(doc.FullFileName, Len(doc.FullFileName) - (Len(doc.FullFileName) - InStrRev(doc.FullFileName, "\")))
Set MyFolder = FSO.GetFolder(DocPath)
For Each myFile In MyFolder.Files
'    ChangeBack = False
    If Left(myFile.Name, 13) = Left(doc.DisplayName, 13) Then
'        If myFile.Attributes = ReadOnly Then
'            ChangeBack = True
'            myFile.Attributes = Normal
'        End If
        myFile.Copy (DocPath & "New Folder\")
'        If ChangeBack Then myFile.Attributes = ReadOnly
    End If
Next
End Sub

I commented out the "read only" code. If you get a message about permission denied try un-commenting that.

 

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes