Read folder name and copy files

Author Message
sbjohal

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 1/10/2012
  • Status: offline
Read folder name and copy files Tuesday, January 10, 2012 11:46 PM (permalink)
0
Hi,
I am new to scripting and want some help from you professional guys. Below is my script, this create one new folder with current data in folder "D:\store\1143" and move .sql file from "D:\store\1143" to new folder created with current date.
Now I want to run this process for other n folders which is existing at "D:\store" using for loop one by one without creating n number of scripts with different folder name. in this loop i also want to call a batch file or SQLCMD to run a MSSQL Job to import SQL files in stores one by one.
 
 strMonth = Month(Date)

If Len(strMonth) = 1 Then
 strMonth = "0" & strMonth
End If

strDay = Day(Date)

If Len(strDay) = 1 Then
 strDay = "0" & strDay
End If

strYear = Year(Date)

strFolderName = "D:\store\1143\" & strMonth & "-" & strDay & "-" & strYear

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.CreateFolder(strFolderName)


Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "D:\store\1143\*.sql" , "D:\Nexvu\DJDevicesFileDump" 

 
Thanks
Sbjohal
 
#1
    59cobalt

    • Total Posts : 979
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Read folder name and copy files Wednesday, January 11, 2012 5:56 AM (permalink)
    0
    sbjohal
    Now I want to run this process for other n folders which is existing at "D:\store" using for loop one by one without creating n number of scripts with different folder name.
    When in doubt, read the documentation.
    sbjohal
    in this loop i also want to call a batch file or SQLCMD to run a MSSQL Job to import SQL files in stores one by one.
    Use the Run() method to execute external commands. Beware that most commandline tools need to run within cmd.exe, so you need to prepend the actual command with "cmd /c" or "%COMSPEC% /c".
     
    #2
      nakra

      • Total Posts : 10
      • Scores: 0
      • Reward points : 0
      • Joined: 3/16/2011
      • Status: offline
      Re:Read folder name and copy files Wednesday, January 11, 2012 7:14 AM (permalink)
      0
      You can use the subfolder property to make a collection of subfolders and iterate over it as you wish.

      Get a hint from here:
       Set oFSO = CreateObject("Scripting.FileSystemObject")
      Set oFolder = oFSO.GetFolder("D:\Store")
      
      ' Get a list of all subfolders and iterate over it
      For Each oSubFolder in oFolder.SubFolders
       ' do something with oSubFolder object
      Next 


      <message edited by nakra on Wednesday, January 11, 2012 7:17 AM>
       
      #3
        sbjohal

        • Total Posts : 2
        • Scores: 0
        • Reward points : 0
        • Joined: 1/10/2012
        • Status: offline
        Re:Read folder name and copy files Thursday, January 12, 2012 1:11 AM (permalink)
        0
        Thanks Guys,
        I will check and update you.
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • New Messages
          • No New Messages
          • Hot Topic w/ New Messages
          • Hot Topic w/o New Messages
          • Locked w/ New Messages
          • Locked w/o New Messages
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9