D
dan dungan
Hi externaldata,
I'm rebuilding a process that resided on a win 3.1 machine
that allowed only 8 character file names.
We want to rename the files using the complete part number as
the file name.
I have about 5,000 files with no file extension. 00-003F,
for example.
I need to find the part number in each file
and rename the file with the part number.
Here are some sample part numbers:
(00-N40L*0800)
(00-M56L*2000)
(02-2174114-0804A)
(T483-15I)
(12-0140**12-061020)
:1001(00-4040L*1001)
We only want the number enclosed by parenthesis.
I think I don't need to read through the whole file.
I want to move to the next file after I've extracted the part number.
I just found out that the part number is not always
on the second line.
Albert D. Kallal supplied the code below and works if the part
number is on the second line of the file and removes the
parenthesis when I rename the file,but I'm confused
about how to find the part number if it isn't on the second line.
Are there any suggestions how to find the part number
and extract it to a variable so I can rename the files?
Sub test9999()
Dim colFiles As New Collection 'To hold file names
Dim strFile As Variant 'To capture the file
name
Dim intFile As Integer 'To count the files to make
sure we only process
file once
Dim strPath As String 'To capture the path
Dim strNewFilename As String 'To capture the new file name
Dim strBuf As String 'To capture the Part Number
'from the second
line of the file
intFile = FreeFile
Call FillDir("C:\Documents and Settings\Analyst\_
My Documents\Work\CNC\Programs\CNC-FEMCO\Test\_
", "", colFiles)
For Each strFile In colFiles
strPath = Left(strFile, InStrRev(strFile, "\"))
Open strFile For Input As #1
Line Input #intFile, strBuf
Line Input #intFile, strBuf
Close intFile
strNewFilename = strPath & Mid(Replace(strBuf, "*", "-")_
, 2, Len(strBuf) - 2)
Debug.Print "old = " & strFile & " new = " & strNewFilename
Name strFile As strNewFilename
Next
MsgBox "done"
End Sub
Thanks,
Dan
I'm rebuilding a process that resided on a win 3.1 machine
that allowed only 8 character file names.
We want to rename the files using the complete part number as
the file name.
I have about 5,000 files with no file extension. 00-003F,
for example.
I need to find the part number in each file
and rename the file with the part number.
Here are some sample part numbers:
(00-N40L*0800)
(00-M56L*2000)
(02-2174114-0804A)
(T483-15I)
(12-0140**12-061020)
:1001(00-4040L*1001)
We only want the number enclosed by parenthesis.
I think I don't need to read through the whole file.
I want to move to the next file after I've extracted the part number.
I just found out that the part number is not always
on the second line.
Albert D. Kallal supplied the code below and works if the part
number is on the second line of the file and removes the
parenthesis when I rename the file,but I'm confused
about how to find the part number if it isn't on the second line.
Are there any suggestions how to find the part number
and extract it to a variable so I can rename the files?
Sub test9999()
Dim colFiles As New Collection 'To hold file names
Dim strFile As Variant 'To capture the file
name
Dim intFile As Integer 'To count the files to make
sure we only process
file once
Dim strPath As String 'To capture the path
Dim strNewFilename As String 'To capture the new file name
Dim strBuf As String 'To capture the Part Number
'from the second
line of the file
intFile = FreeFile
Call FillDir("C:\Documents and Settings\Analyst\_
My Documents\Work\CNC\Programs\CNC-FEMCO\Test\_
", "", colFiles)
For Each strFile In colFiles
strPath = Left(strFile, InStrRev(strFile, "\"))
Open strFile For Input As #1
Line Input #intFile, strBuf
Line Input #intFile, strBuf
Close intFile
strNewFilename = strPath & Mid(Replace(strBuf, "*", "-")_
, 2, Len(strBuf) - 2)
Debug.Print "old = " & strFile & " new = " & strNewFilename
Name strFile As strNewFilename
Next
MsgBox "done"
End Sub
Thanks,
Dan