Hi All,

many people helped me in my previous post, so thanks to them all - and
i now have a script that works for me...and save me a lot of time.(see
bleow)
however - i do have a new issue now - the script works fine until it
see a column with a slash in it (/) - and therefore wont rename the
file - is there an easy way to say that if it sees a / then name the
file to something?

help is much appreciated once again.

Jason

======================================================================
Const csDir = "Path"
Const csExt = "csv"

Set oFS = CreateObject( "Scripting.FileSystemObject" )

For Each oFile In oFS.GetFolder( csDir ).Files
If 0 = StrComp( csExt, oFS.GetExtensionName( oFile.Name ),
vbTextCompare ) Then
renCSVFile oFile, oFS
End If
Next


Sub renCSVFile( oFile, oFS )
On Error Resume Next
Const ForReading = 1
Dim sNewName : sNewName =
Split( oFile.OpenAsTextStream( ForReading ).ReadLine, "," )( 3 )
oFile.Name = sNewName & "-" & RndFileName & ".csv"
End Sub

Function RndFileName()
For x=1 To 8
Randomize
vChar = Int(36*Rnd)
If vChar < 10 Then 'append number
RndFileName = RndFileName & vChar
Else 'else append a letter
RndFileName = RndFileName & Chr(97+(vChar-10))
End If
Next
End Function
=========================================================================

Re: Renaming a CSV file based on content by Pegasus

Pegasus
Fri May 02 05:08:02 CDT 2008


<wills.jason@gmail.com> wrote in message
news:1c18f324-5c70-4b53-b177-247371a405a7@k13g2000hse.googlegroups.com...
> Hi All,
>
> many people helped me in my previous post, so thanks to them all - and
> i now have a script that works for me...and save me a lot of time.(see
> bleow)
> however - i do have a new issue now - the script works fine until it
> see a column with a slash in it (/) - and therefore wont rename the
> file - is there an easy way to say that if it sees a / then name the
> file to something?
>
> help is much appreciated once again.
>
> Jason
>
> ======================================================================
> Const csDir = "Path"
> Const csExt = "csv"
>
> Set oFS = CreateObject( "Scripting.FileSystemObject" )
>
> For Each oFile In oFS.GetFolder( csDir ).Files
> If 0 = StrComp( csExt, oFS.GetExtensionName( oFile.Name ),
> vbTextCompare ) Then
> renCSVFile oFile, oFS
> End If
> Next
>
>
> Sub renCSVFile( oFile, oFS )
> On Error Resume Next
> Const ForReading = 1
> Dim sNewName : sNewName =
> Split( oFile.OpenAsTextStream( ForReading ).ReadLine, "," )( 3 )
> oFile.Name = sNewName & "-" & RndFileName & ".csv"
> End Sub
>
> Function RndFileName()
> For x=1 To 8
> Randomize
> vChar = Int(36*Rnd)
> If vChar < 10 Then 'append number
> RndFileName = RndFileName & vChar
> Else 'else append a letter
> RndFileName = RndFileName & Chr(97+(vChar-10))
> End If
> Next
> End Function
> =========================================================================

Something like
sName = replace(sName, "/", "-")
should do the trick. I recommend you download the
help file script56.chm - it explains all the basic functions
you need for this sort of thing.



Re: Renaming a CSV file based on content by wills

wills
Fri May 02 05:45:27 CDT 2008

On 2 May, 11:08, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> <wills.ja...@gmail.com> wrote in message
>
> news:1c18f324-5c70-4b53-b177-247371a405a7@k13g2000hse.googlegroups.com...
>
>
>
>
>
> > Hi All,
>
> > many people helped me in my previous post, so thanks to them all - and
> > i now have a script that works for me...and save me a lot of time.(see
> > bleow)
> > however - i do have a new issue now - the script works fine until it
> > see a column with a slash in it (/) - and therefore wont rename the
> > file - is there an easy way to say that if it sees a / then name the
> > file to something?
>
> > help is much appreciated once again.
>
> > Jason
>
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> > Const csDir =A0 =3D "Path"
> > Const csExt =A0 =3D "csv"
>
> > Set oFS =3D CreateObject( "Scripting.FileSystemObject" )
>
> > For Each oFile In oFS.GetFolder( csDir ).Files
> > =A0 =A0 =A0 If 0 =3D StrComp( csExt, oFS.GetExtensionName( oFile.Name ),=

> > vbTextCompare ) Then
> > =A0 =A0 =A0 =A0 =A0renCSVFile oFile, oFS
> > =A0 =A0 =A0 End If
> > =A0 =A0Next
>
> > Sub renCSVFile( oFile, oFS )
> > On Error Resume Next
> > =A0 Const ForReading =3D 1
> > =A0 Dim sNewName : sNewName =3D
> > Split( oFile.OpenAsTextStream( ForReading ).ReadLine, "," )( 3 )
> > =A0 =A0 =A0 =A0 oFile.Name =3D sNewName & "-" & RndFileName & ".csv"
> > End Sub
>
> > Function RndFileName()
> > =A0For x=3D1 To 8
> > =A0 =A0Randomize
> > =A0 =A0vChar =3D Int(36*Rnd)
> > =A0 =A0If vChar < 10 Then 'append number
> > =A0 =A0 =A0RndFileName =3D RndFileName & vChar
> > =A0 =A0Else 'else append a letter
> > =A0 =A0 =A0RndFileName =3D RndFileName & Chr(97+(vChar-10))
> > =A0 =A0End If
> > =A0Next
> > End Function
> > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> Something like
> sName =3D replace(sName, "/", "-")
> should do the trick. I recommend you download the
> help file script56.chm - it explains all the basic functions
> you need for this sort of thing.- Hide quoted text -
>
> - Show quoted text -

Great - thanks for the pointer - i'll go and download that now.


Re: Renaming a CSV file based on content by Alex

Alex
Fri May 02 09:32:45 CDT 2008

To save further trouble, you should probably make sure you handle _all_ of
the following characters - they are always illegal in filenames:

< > : " / \ |

I would also be leery of the following characters, because they can be a
source of grief in some situations, especially for shell applications that
may need to deal with the files:

% * & ^ ?


<wills.jason@gmail.com> wrote in message
news:bcf837a8-15b2-4f4c-a6c4-0254c3a678a1@f63g2000hsf.googlegroups.com...
> On 2 May, 11:08, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
>> <wills.ja...@gmail.com> wrote in message
>>
>> news:1c18f324-5c70-4b53-b177-247371a405a7@k13g2000hse.googlegroups.com...
>>
>>
>>
>>
>>
>> > Hi All,
>>
>> > many people helped me in my previous post, so thanks to them all - and
>> > i now have a script that works for me...and save me a lot of time.(see
>> > bleow)
>> > however - i do have a new issue now - the script works fine until it
>> > see a column with a slash in it (/) - and therefore wont rename the
>> > file - is there an easy way to say that if it sees a / then name the
>> > file to something?
>>
>> > help is much appreciated once again.
>>
>> > Jason
>>
>> > ======================================================================
>> > Const csDir = "Path"
>> > Const csExt = "csv"
>>
>> > Set oFS = CreateObject( "Scripting.FileSystemObject" )
>>
>> > For Each oFile In oFS.GetFolder( csDir ).Files
>> > If 0 = StrComp( csExt, oFS.GetExtensionName( oFile.Name ),
>> > vbTextCompare ) Then
>> > renCSVFile oFile, oFS
>> > End If
>> > Next
>>
>> > Sub renCSVFile( oFile, oFS )
>> > On Error Resume Next
>> > Const ForReading = 1
>> > Dim sNewName : sNewName =
>> > Split( oFile.OpenAsTextStream( ForReading ).ReadLine, "," )( 3 )
>> > oFile.Name = sNewName & "-" & RndFileName & ".csv"
>> > End Sub
>>
>> > Function RndFileName()
>> > For x=1 To 8
>> > Randomize
>> > vChar = Int(36*Rnd)
>> > If vChar < 10 Then 'append number
>> > RndFileName = RndFileName & vChar
>> > Else 'else append a letter
>> > RndFileName = RndFileName & Chr(97+(vChar-10))
>> > End If
>> > Next
>> > End Function
>> > =========================================================================
>>
>> Something like
>> sName = replace(sName, "/", "-")
>> should do the trick. I recommend you download the
>> help file script56.chm - it explains all the basic functions
>> you need for this sort of thing.- Hide quoted text -
>>
>> - Show quoted text -
>
> Great - thanks for the pointer - i'll go and download that now.
>

Re: Renaming a CSV file based on content by Pegasus

Pegasus
Fri May 02 09:47:42 CDT 2008


<wills.jason@gmail.com> wrote in message
news:bcf837a8-15b2-4f4c-a6c4-0254c3a678a1@f63g2000hsf.googlegroups.com...
On 2 May, 11:08, "Pegasus \(MVP\)" <I....@fly.com.oz> wrote:
> <wills.ja...@gmail.com> wrote in message
>
> news:1c18f324-5c70-4b53-b177-247371a405a7@k13g2000hse.googlegroups.com...
>
>
>
>
>
> > Hi All,
>
> > many people helped me in my previous post, so thanks to them all - and
> > i now have a script that works for me...and save me a lot of time.(see
> > bleow)
> > however - i do have a new issue now - the script works fine until it
> > see a column with a slash in it (/) - and therefore wont rename the
> > file - is there an easy way to say that if it sees a / then name the
> > file to something?
>
> > help is much appreciated once again.
>
> > Jason
>
> > ======================================================================
> > Const csDir = "Path"
> > Const csExt = "csv"
>
> > Set oFS = CreateObject( "Scripting.FileSystemObject" )
>
> > For Each oFile In oFS.GetFolder( csDir ).Files
> > If 0 = StrComp( csExt, oFS.GetExtensionName( oFile.Name ),
> > vbTextCompare ) Then
> > renCSVFile oFile, oFS
> > End If
> > Next
>
> > Sub renCSVFile( oFile, oFS )
> > On Error Resume Next
> > Const ForReading = 1
> > Dim sNewName : sNewName =
> > Split( oFile.OpenAsTextStream( ForReading ).ReadLine, "," )( 3 )
> > oFile.Name = sNewName & "-" & RndFileName & ".csv"
> > End Sub
>
> > Function RndFileName()
> > For x=1 To 8
> > Randomize
> > vChar = Int(36*Rnd)
> > If vChar < 10 Then 'append number
> > RndFileName = RndFileName & vChar
> > Else 'else append a letter
> > RndFileName = RndFileName & Chr(97+(vChar-10))
> > End If
> > Next
> > End Function
> > =========================================================================
>
> Something like
> sName = replace(sName, "/", "-")
> should do the trick. I recommend you download the
> help file script56.chm - it explains all the basic functions
> you need for this sort of thing.- Hide quoted text -
>
> - Show quoted text -

Great - thanks for the pointer - i'll go and download that now.
============
And here is how you can translate Alex's thoughtful comment into
code. It's best done with a "Regular Expression":

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "[%^&*|/\\:<>?""]"
sName = objRegEx.Replace(sName, "-")