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)
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
|
|
|
|
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)
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".
|
|
|
|
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)
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>
|
|
|
|
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)
Thanks Guys,  I will check and update you.
|
|
|
|