| |

VerySource

 Forgot password?
 Register
Search
View: 1415|Reply: 6

How to select a file and copy it to a folder in the directory where the program is located?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-8 11:00:02
| Show all posts |Read mode
How to select a file and copy it to a folder in the directory where the program is located?
Reply

Use magic Report

0

Threads

14

Posts

14.00

Credits

Newbie

Rank: 1

Credits
14.00

 China

Post time: 2020-12-8 13:30:01
| Show all posts
Dim objfile As New FileSystemObject
objfile.CopyFile App.Path + "\assessDbP.mdb", App.Path + "\another directory\assessDbP"&".mdb"
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-12-8 14:15:01
| Show all posts
filecopy function!

filecopy file path, target path
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-8 14:30:01
| Show all posts
You can also use shell + DOS command
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-8 16:15:01
| Show all posts
FileCopy
Note that the target directory, if the target directory does not exist, an error will occur.
Reply

Use magic Report

0

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-12-8 16:30:02
| Show all posts
You can first check whether the target directory exists, the program can create the directory
Mkdir App.Path + "\directory"' There is an error and continue to the next sentence
FileCopy the original file, App.Path + "\directory"&"\new name"
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 Invalid IP Address

Post time: 2020-12-8 16:45:01
| Show all posts
Judge the existence of the file before FileCopy
    Use FileExists(path+file name) to return boolean
Use the function to build a multi-level directory
  Public Function MakeDir(Path As String) As Boolean
    On Error Resume Next
    Dim o_strRet As String
    Dim o_intItems As Integer
    Dim o_vntItem As Variant
    Dim o_strItems() As String
    o_strItems() = Split(Path, "\")
    o_intItems = 0


    For Each o_vntItem In o_strItems()
        o_intItems = o_intItems + 1


        If o_intItems = 1 Then
            o_strRet = o_vntItem
        Else
            o_strRet = o_strRet&"\"&o_vntItem
            MkDir o_strRet
        End If
    Next
    MakeDir = (Err.Number = 0)
End Function
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list