Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delimited text file using the filenames of files within a folder

Status
Not open for further replies.

Losman500

Technical User
Oct 9, 2007
43
US
I have a script that will read each file on a folder and create a text file which contains the filename and path for each file in the folder.I would like to change this scrip to create a comma delimited file using the filename as the data source for example my file name is:

F2MA 212001800A2 F01 4.tif

I would like the text file to look like this:

"F2MA212001800A2","F01","4",";E:\F2MA 212001800A2 F01 4.tif"

Any help will be appreciated I guess what I really need is a little push understanding the Left, Mid and Right syntax . here is what I have so far:
Code:
Option Explicit

'on error resume next

Dim objFSO
Dim objFolder
Dim colFiles
Dim objSubFolder
Dim objSubFile
Dim strFolder
Dim File
Dim objFile
Dim colFolders
Dim path
Dim filecreate
Dim filetxt
Dim strLine
Dim input
Dim WriteStuff

'Input = InputBox("Enter folder path")

  strFolder = "E:\"
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objFolder = objFSO.GetFolder(strFolder)
  Set colFiles = objFolder.Files
  filetxt= "N:\Resources\Scripts and Stuff\Read Folder Files.txt"
  

Set WriteStuff = objFSO.OpenTextFile(filetxt, 8, True)

For Each File in colFiles
  set objFile = objFSO.GetFile(strFolder & "\" & File.Name)
  WriteStuff.WriteLine(left(objFile.name,40)& "," & objFile.Path)
Next

set objFSO = Nothing
set objFolder = Nothing
set colFiles = Nothing
set objSubFolder = Nothing
set objSubFile = Nothing
set strFolder = Nothing
set File = Nothing
set objFile = Nothing
set colFolders = Nothing
set path = Nothing
set filecreate = Nothing
set filetxt = Nothing
set strLine = Nothing
set input = Nothing
set WriteStuff = Nothing

wscript.Quit

 
Just a thought...an the regular expression can probably be simplified (not an expert with it)

Code:
Option Explicit

Main()

Sub Main()
	Dim RegEx : Set RegEx = New RegExp
	RegEx.Pattern = "([A-Z]+:\\(\w+)\s(\w+)\s(\w+)\s(\w+)\.\w+)"
	RegEx.IgnoreCase = True
	Dim strTemp : strTemp = "E:\F2MA 212001800A2 F01 4.tif"
	If RegEx.Test(strTemp) Then
		WScript.Echo RegEx.Replace(strTemp, """$2$3"",""$4"",""$5"",""$1""")
	End If 
End Sub

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
This pattern may be better suited for paths with sub folders:

"([A-Z]+:.+?\\(\w+)\s(\w+)\s(\w+)\s(\w+)\.\w+)"

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
This may be over my head but I will try it

I'll let you know how I managed. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top