0

I have a folder which contains various tif files.I am using a simple move command which reads as

move "Source path/File name" "Destination path/" 

I have tried a command which reads as:

move "Source path/File 1, File 2. File 3" "Destination Path/"

I am looking for a similar formula which can help me out. The reason why this code is important for me

In a scenario where iam moving only one file to destination folder In another scenario, I have to choose 3 or more files to another destination folder. If I do this with generic formula it takes a longer time to accomplish.

Please do suggest on this.

move "Source path/File 1, File 2. File 3" "Destination Path/"

In a scenario where I am moving only one file to destination folder. In another scenario, I have to choose 3 or more files to another destination folder. Example: Sample

If I do this with generic formula it takes a longer time to accomplish.

5
  • please refer THIS <stackoverflow.com/questions/38456928/…> . If there is a problem then bring it up. Commented Feb 11, 2019 at 7:31
  • Thanks! but what i need to achieve is selective files to selective folders only Move "026-0026.tif, 027.tif, 028.tif, 030.tif" "D:\Test\32\" Commented Feb 11, 2019 at 7:36
  • @joe what you need is to show what you already have tried so far. Edit your question and show your code. Because this is no free code writing service it is necessary to show either what you have tried so far and where you got stuck or errors (by showing your code) or at least to show what you have researched and the effort you made. Otherwise it is just asking us to do all the work for you. Reading How to Ask might help you to improve your question. Commented Feb 11, 2019 at 7:40
  • I have a program which I use. It requires files to be moved listed in worksheet range and allows selection of range thru input-box and opens up dialog box to select source and destination folders. If it serves your purpose, I can submit my answer. Commented Feb 11, 2019 at 8:27
  • Thanks! I appreciate your thoughts and help. It will not achieve my real purpose in-turn to save time and repeated action. Commented Feb 11, 2019 at 8:37

1 Answer 1

1

You might try the code below.

Sub MoveFiles()

    Dim DestinationPath As String
    Dim SourcePath As String
    Dim FileNames As String
    Dim Sp() As String
    Dim i As Integer

    SourcePath = Environ("USERPROFILE") & "\Desktop"
    DestinationPath = "H:\TestFolder"
    FileNames = "File1.txt,File2.txt,File3.txt"

    If Right(SourcePath, 1) <> "\" Then SourcePath = SourcePath & "\"
    If Right(DestinationPath, 1) <> "\" Then DestinationPath = DestinationPath & "\"
    If Len(FileNames) Then
        Sp = Split(FileNames, ",")
        For i = 0 To UBound(Sp)
            Sp(i) = Trim(Sp(i))
            If Len(Dir(SourcePath & Sp(i))) Then
                Name SourcePath & Sp(i) As DestinationPath & Sp(i)
            End If
        Next i
    End If
End Sub

Set the Source and Destination paths according to your system. Enter as many or as few file names in one comma separated string. All named files will be moved if they exist at the SourcePath. If the destination path doesn't exist an error will occur.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks! I have added an example. This might help to understand my request.
My code will only require very little change to change the file names at the time of copying. You should be able to do it yourself. But to extract the names from your worksheet is a major job and not covered by your question.
Thanks! Iam looking for simple formula in CMD window. In my example "cmd to acheve", the formula will be created and run on CMD. But there is some logic missing to achieve this.Request expert tweak on this.
You want a DOS solution to enter from the Command Prompt. Amend your question to exclude both VBA and Excel. Your question isn't related to either.
HI, Hope some one assist on this.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.