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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display first 6 characters of a filename?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm a beginning programmer trying to learn VBScript.
I need to grab a file from a folder and display only the first 6 characters of the filename. Example:

folder = C:\temp
filename = 100452ATestFile.txt
want to display in a message box: 100452

Not sure of how to do this. Any help would be appreciated.
 
Great help! How would I create a folder with the first six characters of the filename?
look in the directory and get file:
100452ATestFile.txt

create a folder using the first 6 characters of the filename:

FOLDER NAME would be 100452

 
Try this:

'Get the filename

filename = "100452ATestFile.txt"
newfoldername = left(filename,6) 'Takes the first 6 characters off the string

'Create a new folder

Dim fileobj,newfolder
Set fileobj = Server.CreateObject ("Scripting.FileSystemObject") ' Creates a file sytem object
Set newfolder = fileobj.CreateFolder(newfoldername) ' the file system object creates a new folder using the string info stored in "newfoldername"




you can optionally specify a file path where you want the folder created:

'Before the Dim fileobj,newfolder statement, put this
newfoldername = "c:\program files\myfolders\"+newfoldername


Hope this helps ;)
AT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top