473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do I access series of files in perticular folder

I need to access serially all files in perticular folder eg. C:\xls files
In 'Xls files' folder in 'C' drive there are no of XLS files i need to open them all one by one & update them.
Is there any concept like pointer in VB wherein I could increase ptr that will then point to next file in same folder.
Jan 8 '07 #1
2 1497
I need to access serially all files in perticular folder eg. C:\xls files
In 'Xls files' folder in 'C' drive there are no of XLS files i need to open them all one by one & update them.
Is there any concept like pointer in VB wherein I could increase ptr that will then point to next file in same folder.

You may be looking at the "Dir" Function

Here's the example in the help file:
This example uses the Dir function to check if certain files and directories exist. On the Macintosh, “HD:” is the default drive name and portions of the pathname are separated by colons instead of backslashes. Also, the Microsoft Windows wildcard characters are treated as valid file-name characters on the Mac. However, you can use the MacID function to specify file groups.


Expand|Select|Wrap|Line Numbers
  1. Dim MyFile, MyPath, MyName
  2. ' Returns "WIN.INI" (on Microsoft Windows) if it exists.
  3. MyFile = Dir("C:\WINDOWS\WIN.INI")    
  4.  
  5. ' Returns filename with specified extension. If more than one *.ini
  6. ' file exists, the first file found is returned.
  7. MyFile = Dir("C:\WINDOWS\*.INI")
  8.  
  9. ' Call Dir again without arguments to return the next *.INI file in the 
  10. ' same directory.
  11. MyFile = Dir
  12.  
  13. ' Return first *.TXT file with a set hidden attribute.
  14. MyFile = Dir("*.TXT", vbHidden)
  15.  
  16. ' Display the names in C:\ that represent directories.
  17. MyPath = "c:\"    ' Set the path.
  18. MyName = Dir(MyPath, vbDirectory)    ' Retrieve the first entry.
  19. Do While MyName <> ""    ' Start the loop.
  20.     ' Ignore the current directory and the encompassing directory.
  21.     If MyName <> "." And MyName <> ".." Then
  22.         ' Use bitwise comparison to make sure MyName is a directory.
  23.         If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
  24.             Debug.Print MyName    ' Display entry only if it
  25.         End If    ' it represents a directory.
  26.     End If
  27.     MyName = Dir    ' Get next entry.
  28. Loop
  29.  
  30.  
Jan 8 '07 #2
seshu
156 100+
Hi this is seshu
i saw ur query i dont know wat u are trying to do on each file i mean access means there are many thigs but here i have code to check whether the file exists or not and the folder, sub folder exists or not if exists then the application will copye a file from the folder u specified else creates that path and then copies and here is the code
Expand|Select|Wrap|Line Numbers
  1. Dim fsys As New FileSystemObject
  2. Dim fsys1 As New FileSystemObject
  3. Dim fd As Folder
  4. Dim fd1 As Folder
  5. Dim fls As Files
  6. Dim f As File
  7. Dim str As String
  8. Dim str1 As String
  9. Dim str2 As String
  10. Set fd = fsys.GetFolder(path)
  11. Set fls = fd.Files
  12. For Each f In fls
  13.     'Debug.Print f.Name
  14.         str = Split(f.Name, "_")(1)
  15.         str1 = Split(f.Name, "_")(3)
  16.         str3 = "path" & str
  17.         str2 = "path" & str & "\" & str1
  18.      If fsys1.FolderExists(str3) Then
  19.          If fsys1.FolderExists(str2) Then
  20.             fsys.CopyFile f.Path, "destination path\" & str & "\" & str1 & "\", True
  21.         Else
  22.             fsys1.CreateFolder "folder to be created path" & str & "\" & str1
  23.             fsys.CopyFile f.Path, "destination path\" & str & "\" & str1 & "\", True
  24.         End If
  25.       Else
  26.             fsys1.CreateFolder "folder to be created path" & str
  27.      End If
  28. Next
  29. End Sub
here my file name are like abc_def.txt that is the reason y i took split function
hope u will understand the code
regards
seshu
Jan 9 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jaunty Edward | last post by:
Hi, My problem is a little advance I feel, please check it and guide me if you can. I have a lot of similar format text files, that has name in the first line then age in forth line second and...
4
by: RichB | last post by:
Hello, The .NET application I have just installed at a client web site is throwing a strange error. At first the applications works without any problems, but after 10 mins or so Access denied...
17
by: rdemyan via AccessMonster.com | last post by:
With A2003, I'm having trouble accessing files in a folder on another computer where back-end files, update files, etc are located. Here's the scenario: 1) Computer #1 - A2003 2) Computer #2 -...
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
2
by: john_aspinall | last post by:
For a kick off sorry if this is the wrong forum, Ill go on the Access one if Im not on the right board! Anyways, Ive got a problem and am not sure if its going to be solved programatically using...
1
seshu
by: seshu | last post by:
Hi everybody this is seshu long back i remember me posting a code in vb how write a for each loop and getting the names of ech file in a perticular folder but today i want a...
23
nehashri
by: nehashri | last post by:
hi i am designing a database using Ms Access and ASP. i have 3 tables in access namely 'PERSONAL', other as 'POLICY' and 3rd one is named as 'STAFF'. in the contact table i have ID, Name, Children...
6
by: rlntemp-gng | last post by:
I need to extract information from some Excel files but am stuck with part of it: As an example, I have the following Excel File that has 3 tabbed sheets: FileName: ...
4
by: chimambo | last post by:
I have 2 problems: 1. I want to import a single text file into an access table using a Macro. I am however getting an error that I need to put a specification name argument. What does this mean?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.