Skip to content

Instantly share code, notes, and snippets.

@Tucker-Eric
Last active October 29, 2015 20:43
Show Gist options
  • Save Tucker-Eric/e78db48e461ac0fd8db7 to your computer and use it in GitHub Desktop.
Save Tucker-Eric/e78db48e461ac0fd8db7 to your computer and use it in GitHub Desktop.
Arrange Files Into Client Folders
Dim fso,f,strPathBuild,destFolder,clientFolder,newFile
'This is where we searching for the files to move
'This is also where the sub directories are located
destFolder = "F:\envista_data_files\Client Data"
'Create the File System Object that will do all file/folder manipulations
Set fso=CreateObject("Scripting.FileSystemObject")
'Create the folder object we are going to start searching in
Set f = fso.GetFolder(destFolder)
'Regular Expression to identify client id/code
Set re = new regexp
'Pattern: Starts a string, followed by a space.
'Capture Group the captial letters (Min 1, no max) followed by an optional digit
'Followed by a string and at least one character
re.Pattern = "^.+\s([A-Z]+[0-9]?)\s.+$"
'Start our loop for files in the folder
'Automatically exclused folders
For Each file in f.Files
'Replace the file name with our folder name to get path to copy or build/copy
clientFolder = re.Replace(file,"$1")
'This is the path we are going to place this file
strPathBuild = destFolder & "\" & clientFolder
'If the folder doesnt exist we create it
If Not fso.FolderExists(strPathBuild) Then
fso.CreateFolder strPathBuild
End If
'Now create the file fullpath name by isolating just the file name with Replace
newFile = strPathBuild & "\" & Replace(file,destFolder,"")
'If the file doesnt already exist there then we are moving it there
If Not fso.FileExists(newFile) Then
fso.MoveFile file, newFile
Else
'If the file already exists we delete it from the root directory we are starting our search in
fso.DeleteFile file
End If
Next
Set f = Nothing
Set fso = Nothing
cd C:\local_bats
ftp -i -s:get_files.ftp
copy *.pdf F:\envista_data_files\
del *.pdf
copy *.xls F:\envista_data_files\
del *.xls
copy *.xlsx F:\envista_data_files\
del *.xlsx
copy *.zip F:\envista_data_files\
del *.zip
cscript extract_client_data.vbs
cscript arrange_files.vbs
Dim fso,f,strPathBuild,startFolder,destFolder,clientFolder,newFile
'This is the folder we are looking for our zip files in that we are extracting
startFolder = "F:\envista_data_files"
'This is where the contents of the zip file will be placed
destFolder = "F:\envista_data_files\Client Data"
'Create our File System Object that will do all file manipulating
Set fso=CreateObject("Scripting.FileSystemObject")
'Create folder object so we can search in our start folder for zip files
Set f = fso.GetFolder(startFolder)
'Crete regex object to match zip files
Set re = new regexp
re.Pattern = "^.*\.zip$"
'Handle each zip file
For Each file in f.Files
'If that control file exists then delete it
If fso.FileExists(destFolder & "\ControlFile.INVOICING.csv") Then
fso.DeleteFile destFolder & "\ControlFile.INVOICING.csv"
End If
'Test the regexp for zip and then unzip contents to our destination folder
If re.Test(file) = true Then
WindowsUnZip fso.GetAbsolutePathName(file) , destFolder
'Move the actual zip file to Extracted Files dir located in our start folder
fso.MoveFile file, Replace(file,startFolder,startFolder& "\Extracted Files")
End If
'Delete the control file at the end
If fso.FileExists(destFolder & "\ControlFile.INVOICING.csv") Then
fso.DeleteFile destFolder & "\ControlFile.INVOICING.csv"
End If
Next
Set f = Nothing
Set fso = Nothing
Function WindowsUnZip(sUnzipFileName, sUnzipDestination)
'This script is provided under the Creative Commons license located
'at http://creativecommons.org/licenses/by-nc/2.5/ . It may not
'be used for commercial purposes with out the expressed written consent
'of NateRice.com
Set oUnzipFSO = CreateObject("Scripting.FileSystemObject")
If Not oUnzipFSO.FolderExists(sUnzipDestination) Then
oUnzipFSO.CreateFolder(sUnzipDestination)
End If
With CreateObject("Shell.Application")
.NameSpace(sUnzipDestination).Copyhere .NameSpace(sUnzipFileName).Items
End With
Set oUnzipFSO = Nothing
End Function
open <% FTP %>
<% FTP_USERNAME %>
<% FTP_PASSWORD %>
cd /toengage/nav
mget * F:\envista_data_files\
mdelete *
close
quit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment