nyee84
asked on
add text filename into dataset.
My current program will copy txt files from c:A folder into c:\B folder however i need to check the the same text file exist in folder B or not. The current method i am using is the file.exist and it was very unfortunate that my c:\B folder got 2000 overfile and the current method(file.eixst) taking long time and which is not acceble for the user also. One vb.net expert adviced me that we can add all the txtfilenames into dataset and while moving files into c:\B, each filename need to be comapared against the dataset and will eliminate the process time also . is it possible? and pls provide the code also.
my sample text file name is SD1245-4424.txt. Pls advice
my sample text file name is SD1245-4424.txt. Pls advice
1) What type of application are you creating?
2) What .NET version do you have?
3) Are you going to distribute this to many different types of users?
4) Would you be willing to interoperate with a COM library.
Here is a previous C# question, but I also have a VB.NET class that handles doing very fast LogParser file queries:
https://www.experts-exchange.com/questions/21796480/Using-progress-bar-while-scanning-folders.html
Bob
2) What .NET version do you have?
3) Are you going to distribute this to many different types of users?
4) Would you be willing to interoperate with a COM library.
Here is a previous C# question, but I also have a VB.NET class that handles doing very fast LogParser file queries:
https://www.experts-exchange.com/questions/21796480/Using-progress-bar-while-scanning-folders.html
Bob
ASKER
Hi tolg,
Only one user going to use my program and basically the program should copy all the files from c:\A folder into C:\B folder and while coping each files in c:\A
need to compare agianst all the files in c:\B , if same text file exist in c:\B then i got move the existing file into C:\archive folder and new file will be copied to the c:\B folder.
My c:\A can have max of 200 files need to copy to C:\B and need check agianst all the filename in C:\B(1200 files), pls explain in detail how can i use array list for this scenario.
If the same text file exist in c:\B folder, then i need to copy the existing files into c:\archive folder. i also have issue with "concurrency" cos while moving file into archive folder, the file might be opened by some of my user, so what will happen to the program, how can i over this issue. Since i am very new programming pls explain everything in detail .. Thanks
Hi LearnedOne,
1)vb.net windows application
2)1.1
3)No ,Single user
4)not really know much about com library.
Thanks
Only one user going to use my program and basically the program should copy all the files from c:\A folder into C:\B folder and while coping each files in c:\A
need to compare agianst all the files in c:\B , if same text file exist in c:\B then i got move the existing file into C:\archive folder and new file will be copied to the c:\B folder.
My c:\A can have max of 200 files need to copy to C:\B and need check agianst all the filename in C:\B(1200 files), pls explain in detail how can i use array list for this scenario.
If the same text file exist in c:\B folder, then i need to copy the existing files into c:\archive folder. i also have issue with "concurrency" cos while moving file into archive folder, the file might be opened by some of my user, so what will happen to the program, how can i over this issue. Since i am very new programming pls explain everything in detail .. Thanks
Hi LearnedOne,
1)vb.net windows application
2)1.1
3)No ,Single user
4)not really know much about com library.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could you elucidate the term try again later" method clearly.
Thanks
Thanks
ASKER
Hi Bob,
What will be the advange of using logparsor for my scenario. Kindly advice.
What will be the advange of using logparsor for my scenario. Kindly advice.
By saying try again later
I mean catch the exception and try again :)
Here is a sample code
private void copyFunction
try
System.IO.File.Copy("c:\b\ " & candidateFileToCopy, "c:\archive\" & candidateFileToCopy)
catch exp as exception
'Suppose the file is inuse and the copy operation could not be completed. Then use the below code
system.threading.thread.sl eep(5000) ' Sleep for 5 seconds.
copyFunction() 'İt will call itself recursively until the copy operation is successfully completed.
end try
end function
If you can put the above code in a different thread it will be better ;)
I mean catch the exception and try again :)
Here is a sample code
private void copyFunction
try
System.IO.File.Copy("c:\b\
catch exp as exception
'Suppose the file is inuse and the copy operation could not be completed. Then use the below code
system.threading.thread.sl
copyFunction() 'İt will call itself recursively until the copy operation is successfully completed.
end try
end function
If you can put the above code in a different thread it will be better ;)
ASKER
Hi tog,
Kindly explain the use of arraylist in detail for the below scenario . c:\projects folder files need to move into C:\SE or c:\SA
base on the text filenames in c:\projects folder.
My filename will be as follows SA12345_07-Feb-06_0831.txt
SE24555_05-Mar-06_12.31.tx t,
so if my file starts with SE then need to move the files into C:\SA folder and if the filename starts with SE then i need to move the file into C:\SE. While moving fle into designated folders i need to check whether same file exist in desidnated folder or not.
The current method is i will all the files from both SA and SE into an arraylist and while moving files from c:\projects,
i will check against my arraylist and files which is of a earlier data need to move into c:\archive folder.
For ex my exiting file in c:\SE folder is SA12345_07-Feb_06_0831
My file need to move from c:\project also SA12345_07-Feb_06_1031. earliest time and date is obviously SA12345_07-Feb_06_0831, moving into c:\archive.
Inorder to do this task, i need to store all the filenames from C:\se and c:\SA into an arraylist while moving files from c:\projects, i need to compare with the arraylist also .
Which method is faster? storing in sql server database table or storing in arraylist. File size in c:\SE and c:\SA growing also. Kindly advice
Kindly explain the use of arraylist in detail for the below scenario . c:\projects folder files need to move into C:\SE or c:\SA
base on the text filenames in c:\projects folder.
My filename will be as follows SA12345_07-Feb-06_0831.txt
SE24555_05-Mar-06_12.31.tx
so if my file starts with SE then need to move the files into C:\SA folder and if the filename starts with SE then i need to move the file into C:\SE. While moving fle into designated folders i need to check whether same file exist in desidnated folder or not.
The current method is i will all the files from both SA and SE into an arraylist and while moving files from c:\projects,
i will check against my arraylist and files which is of a earlier data need to move into c:\archive folder.
For ex my exiting file in c:\SE folder is SA12345_07-Feb_06_0831
My file need to move from c:\project also SA12345_07-Feb_06_1031. earliest time and date is obviously SA12345_07-Feb_06_0831, moving into c:\archive.
Inorder to do this task, i need to store all the filenames from C:\se and c:\SA into an arraylist while moving files from c:\projects, i need to compare with the arraylist also .
Which method is faster? storing in sql server database table or storing in arraylist. File size in c:\SE and c:\SA growing also. Kindly advice
If it is not, then when the program starts get the names of the files in c:\B =>
dim files() as string = system.IO.Directory.GetFil
This will give you an string array but arrays are static (you can't add new item to it -at least not easily)
Therefore, create an arraylist,
dim xx as new arraylist
in a loop, insert all the files you have in to the arraylist
for i as integer = 0 to files.length-1
xx.add(files(i))
next
then use the contains method before coping
if not xx.contains("abc.txt") then
xx.add("abc.txt")
copy from c:\a to c:\b
end if
----
If multiple instances of your program can run from different machines and works on the same folder (c:\B)
then use a filesystemwatcher and add the newly copied files to your arraylist