Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with easy ???(newbie)

Status
Not open for further replies.

GOOGE

Technical User
Jun 20, 2001
36
0
0
NZ
please look at the code beloow and tell my what i have to do, questions follow the code........

Public Sub form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)

If Data.GetFormat(vbCFFiles) Then Text1.Text = Data.Files(1)

FileCopy Text1.Text, "c:\windows\desktop\"
End Sub

the question is. when i drag a file onto the form i want it to copy straight to the address given,in this case it windows\desktop, the problem i have is i dont know how to get the file name in data.files(1) to copy the file so it will be the same name and extension,is there a way to to tell the for that the file name is the string to the right of the last backslash (\).

thanks

james cuttance
 
hi,

If I understood your question correctly, the answer is:

-----------------------------------------------------------
Mid$(Data.Files(1), InStrRev(Data.Files(1), "\") + 1)
-----------------------------------------------------------

Sunaj
 
i tried it but it didnt work maybe im doing somthing wrong.

what i want to do is to copy th file to a directory but when i do i cant get the file name to be the same as the original with the code i am using . if i dran sample.exe then i want it to be sample.exe in the new directory so i have to find away of reading the everything after the last \ which would be the file name in this case. if i change the code to the following.....

FileCopy Text1.Text, "c:\windows\desktop\sample.txt"

then everything i copy is copied as sample dot text even if it is an exe or zip . i hope i have made it more clear .

sorry but i do appreciate the help
 
try this portion of code:

Do While Not FileNameFound
strFileName = Right(strFullPath, CntFromRight)
If Left(strFileName, 1) = "\" Then
strFileName = Right(strFileName, Len(strFileName) - 1)
FileNameFound = True
End If
CntFromRight = CntFromRight + 1
Loop

strFileName = Left(strFileName, Len(strFileName) - 4)

What this does is checks each character starting at the right until it finds a "\". Then is takes the rightmost characters except for the "\" including the File extension. If you want the extension, leave the string alone, however I stripped of the extension by taking the leftmost characters up to 4 less than the string's length. I hope this helps.
 
hi,

Idon't understand that you cannot get my code working. Here's an illustration:

------------------------------------------------------------
Dim MyFile As String, NewDir As String

NewDir = "c:\temp\"
MyFile = "c:\windows\desktop\sample.txt"

FileCopy MyFile, NewDir & Mid$(MyFile, InStrRev(MyFile, "\") + 1)
------------------------------------------------------------

If you can't get it working: Try and debug the project. Put a break point at the line with the FileCopy put a watch on everything after the comma. It is showing the correct file and path?

Sunaj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top