• Move CSV Files from source folder including sub-folders

    Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Move CSV Files from source folder including sub-folders

    Author
    Topic
    #507944

    I have various CSV files in folder C:data as well as within the sub-folder for eg C:dataTBBR1, C:dataTBBR2 etc

    I have code to move the CSV files from the source directory to a folder called C:old data

    However, when I run the macro the csv files are not moved

    It would be appreciated if someone could kindly amend my code

    Viewing 6 reply threads
    Author
    Replies
    • #1588978

      Hi Howard

      ..I’m sure we’ve done this before, so I’m looking back through previous example files that moved csv files.
      I’ll post it when I find it (and test it).

      zeddy

      • #1588992

        Hi Zeddy

        You did do something similar, but for some unknown reason, the csv files in the folder C:data and its sub-folders are not being moved

        Look forward to receiving your update

        Regards

        Howard

    • #1589001

      Hi Howard

      Your posted file will work if you put the right name in for your source folder.
      Your entry for your source folder..
      C:datal
      ..may look correct, but if you put your glasses on, you will see that you have typed the ‘pipe’ character ‘|’ rather than, perhaps, the digit 1 as in data1????

      I tested the file, with my own test folders and 100 sample csv files in a few subfolders, and it moved them in a blink of an eye.

      zeddy

    • #1589017

      Thanks for pointing out the error Zeddy

      The data now copies the csv files from the source folder as well as the sub-folders

      However, I do not want the csv files to remain in the source folder and sub-folder

      Kindly amend the macro to do this

      Howard

      • #1589022

        Hi Howard

        I used the same file you posted.
        When I did my test with >100 csv files in my source folder with a couple of subfolders, ALL of the files were moved to my specified destination folder. The sub folders in the source folder had NO files in them after the routine ran i.e. ALL csv files were moved.
        Can you check yours again?

        zeddy

    • #1589047

      Hi Zeddy

      Some of the csv files are being moved

      I have attached a sample csv file that is not being moved (I had to save as an xls file as this forum does not allow csv files to be uploaded)

      Please test and advise

      Howard

      • #1589078

        Hi Howard

        ..I’ll have a look and see if I can work out what is going on.

        zeddy

    • #1589082

      Hi Zeddy

      Thanks very much. It is very strange that files saved as CSV files are being moved, but those that are downloaded automatically with a .csv extension are not being moved

      Hopefully you will find a solution

      • #1589101

        Hi Howard

        I saved your file as a csv file in my test source folder, along with 2 sub folders and over 100 csv test files.
        ALL files were moved.
        So I cannot replicate your issue.

        Can you double-check the filenames for your ‘downloaded’ csv files?
        The routine is just using a simple ‘character-pattern-match’ for the filenames to be moved, i.e. doesn’t check whether the files are actually csv files, just if the filename matches what you have chosen.

        zeddy

        • #1589141

          Hi Zeddy

          I finally resolved the problem

          The code below was in ”

          Code:
           Kill zDestFile 

          When I took out the ” and run the code, the old CSV files were moved. The reason was that these already existed in the old data file folder

          Howard

          • #1589172

            Hi Howard

            It’s coming back to me now. Slowly.
            I seem to remember at one time we wanted to NOT move files if they were ALREADY in the destination folder.
            Then, another time, we wanted to move them and overwrite any existing files if they were already in the destination..
            And then another time, we would only overwrite the files if the ones being moved were newer files.
            And then we had a file which allowed us to ignore moving files before a chosen date etc etc etc.

            I’ll have a look and see what the latest file was.

            ..many thanks for clearing up the mystery!

            zeddy

    • #1589135

      Thanks for your help and input Zeddy

      Will download a file when I am at the office later this morning (4;55am over here) to determine file name. The macro moves all the files saved as CSV files, except the downloaded files containing a csv extension

      I have just noticed, that the downloaded csv files are all old csv files. Does the code , exclude csv files beyond a certain date?

      Howard

    • #1589179

      Hi Zeddy

      You have an excellent memory

      I am glad I managed to resolve the issue

      Howard

    Viewing 6 reply threads
    Reply To: Move CSV Files from source folder including sub-folders

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: