Consulting

Results 1 to 6 of 6

Thread: Move Files to SubFolders

  1. #1
    VBAX Regular
    Joined
    Jun 2017
    Posts
    26
    Location

    Move Files to SubFolders

    I've exhausted my efforts to solve this on my own. I'm fairly new to scripting and I'm hoping someone with more experience can point me in the right direction.

    I have a script that creates thousands of images in one folder. At the end of the script I'd like to sort the images into subfolders. The script successfully creates the subfolder and I can move the file if i use the exact path. But I need something that will work on variable filenames.

    When i save the file i use this script with success...
    "-SaveRenderWindowAs ""C:\Rendermation\renders\" & folderIdx.name & "_AccentGem" & ".png" & """"
    The folderIdx.name successfully uses a name that changes per file.

    When I move the file into its subfolder...
    This script works fine (defining the exact path)
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.MoveFile "C:\Rendermation\Renders\perspective_Ring_Solitaire_Marquise_6X3mm.3dm.png" , "C:\Rendermation\Renders\Ring_Solitaire_Marquise_6X3mm.3dm\"


    However, if i replace this line, it fails...

    fs.MoveFile "C:\Rendermation\Renders\perspective_" & folderIdx.name, "C:\Rendermation\Renders\" & folderIdx.name & "\"


    This is the error.
    "Microsoft VBScript runtime error"
    "Object required:'folderIdx'"


    Any ideas?

    Jill

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    Surely, folderIdx.name refers to perspective not to Ring_Solitaire_Marquise_6X3mm.3dm.png
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Jun 2017
    Posts
    26
    Location
    folderIdx.name is this portion
    Ring_Solitaire_Marquise_6X3mm.3dm

    I add the perspective when i save the file.

    This is the portion that creates the folder where I want to move the files.

    For Each folderIdx In files

    'create folder to save the renders
    If Not folderexists(strFolder & "\renders\" & folderidx.name) Then
    mkdir strFolder & "\renders\" & folderidx.name
    End If

    Next


    Im attaching a screencap of the directory from which I want to move the files. You can see the folder that has been created.
    Attached Images Attached Images

  4. #4
    VBAX Regular
    Joined
    Jun 2017
    Posts
    26
    Location
    I did notice i was missing the .png from the source.

    Set fs = CreateObject("Scripting.FileSystemObject")


    fs.MoveFile "C:\Rendermation\Renders\perspective_" & folderIdx.name & ".png", "C:\Rendermation\Renders\" & folderIdx.name & "\"

    But i still get the same error...

    "Microsoft VBScript runtime error"
    "Object required:'folderIdx'"

  5. #5
    VBAX Regular
    Joined
    Jun 2017
    Posts
    26
    Location
    I'm still spinning my wheels.

    I will try to explain the issue again in detail.

    I have a script that runs
    For Each folderIdx In files

    These files are located in the following directory
    C:\Rendermation\


    At first there is only one file Ill call "Solitaire"

    A subfolder with this name is created programatically
    C:\Rendermation\render\solitaire
    This subfolder is created by using the following code

    For Each folderIdx In files

    If Not folderexists(strFolder & "\renders\" & folderidx.name) Then
    mkdir strFolder & "\renders\" & folderidx.name
    End If


    Next




    The script then opens all files in that initial directory (C:\Rendermation\) and saves them with a prefix.
    bluestone_solitaire
    perspective_solitaire
    side_solitaire
    solitaire (this is my original file)
    throughfinger_solitaire
    topangle_solitaire

    The script then creates images based on that prefix that are saved in a subfolder
    C:\Rendermation\renders

    At the end of this process there are 18 files for each prefix. So if i have one original file (Solitaire) then the result is 108 image files. However if I drop 5 original files then I get 30 prefix files and 540 images.

    So i added code to sort through the files. And I finally got it to work on some of the files.

    This is example of one of the blocks of code for one of the prefixes.

    If fileexists(strFolder & "\renders\bluestone_" & folderIdx.name & ".png") Then

    fs.MoveFile "C:\Rendermation\Renders\bluestone_" & folderIdx.name & ".png", "C:\Rendermation\Renders\" & folderIdx.name & "\"

    If fileexists(strFolder & "\renders\bluestone_" & folderIdx.name & "_Metal1.png") Then
    fs.MoveFile "C:\Rendermation\Renders\bluestone_" & folderIdx.name & "_Metal1.png", "C:\Rendermation\Renders\" & folderIdx.name & "\"
    End If

    If fileexists(strFolder & "\renders\bluestone_" & folderIdx.name & "_Metal2.png") Then
    fs.MoveFile "C:\Rendermation\Renders\bluestone_" & folderIdx.name & "_Metal2.png", "C:\Rendermation\Renders\" & folderIdx.name & "\"
    End If

    If fileexists(strFolder & "\renders\bluestone_" & folderIdx.name & "_CenterGem.png") Then
    fs.MoveFile "C:\Rendermation\Renders\bluestone_" & folderIdx.name & "_CenterGem.png", "C:\Rendermation\Renders\" & folderIdx.name & "\"
    End If

    If fileexists(strFolder & "\renders\bluestone_" & folderIdx.name & "_SideGem.png") Then
    fs.MoveFile "C:\Rendermation\Renders\bluestone_" & folderIdx.name & "_SideGem.png", "C:\Rendermation\Renders\" & folderIdx.name & "\"
    End If

    If fileexists(strFolder & "\renders\bluestone_" & folderIdx.name & "_AccentGem.png") Then
    fs.MoveFile "C:\Rendermation\Renders\bluestone_" & folderIdx.name & "_AccentGem.png", "C:\Rendermation\Renders\" & folderIdx.name & "\"
    End If

    End If



    The problem .... this code does not work until the script creates the images for the original file (Solitaire) in the list below. So in theis example when it completes Solitaire, it successfully moves all the files into their respective subfolder
    C:\Rendermation\render\solitaire

    However any prefix files that fall alphabetically after Solitaire never get sorted.


    bluestone_solitaire
    perspective_solitaire
    side_solitaire
    solitaire (this is my original file)
    throughfinger_solitaire doesnt get sorted
    topangle_solitaire doesnt get sorted


    I believe the problem is the folderidx.name doesnt initiate until after creating the images for that file. I have tried so many things to solve this and I am totally lost.

    My approach to do this as one script may be all wrong. I've also tried to separate it into two scripts, one that creates the images and one that sorts the files, but I have not been able to figure out how to create something that sorts the files based on the name of the subfolder within the directory. I'm including a screenshot of the directory in case anyone has ideas.

    Thanks in advance to anyone who has ideas.
    Jill
    Attached Images Attached Images

  6. #6
    VBAX Regular
    Joined
    Jun 2017
    Posts
    26
    Location
    This was solved by mdmackillop (the genius!) in the thread below. Thanks so much for all the help.

    Jill

    http://www.vbaexpress.com/forum/show...hes-foldername

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •