Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


comparing file names, etc

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2917
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> comparing file names, etc
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 comparing file names, etc - 5/8/2005 5:27:20 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
we need a function that is going to compare the names of the two files , if the file names match it implies there are two files ....it should then say writeto logs saying the number of files....

now that we know thr is more than one file then the comparison should be made for the filenames (character by character ...using wildcards) as the file name also has the date ....on the basis of that date it should decide which file is of older date and move it out of the directory.

like this it should do for say file type A, B, C implies there are number of file types and we need to check if multiple versions of each of the file types exist...
 
 
Post #: 1
 
 Re: comparing file names, etc - 5/8/2005 7:37:48 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Could you give us some examples (eg: source directory and file, and destination directory and file) ?

(in reply to abhinav75)
 
 
Post #: 2
 
 Re: comparing file names, etc - 5/9/2005 7:50:19 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
Question, If you are looking to compare 2 files to see they match, why would you need to do a character by character compare if you already know they match?

i.e. c:\folder1\File1.txt = c:\folder2\file1.txt while c:\folder1\File1-05-06-2005.txt <> c:\folder2\file1-05-07-2005.txt

if you added the date to the file name then you are morelikely to get 2 different file names. If you factor in the date and time, the likely hood that you will have the same names is even less likely.

(in reply to abhinav75)
 
 
Post #: 3
 
 Re: comparing file names, etc - 5/9/2005 4:26:29 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
The name is somethg like say xyz040605.dat and xyz050505. dat
that
is when we need to check that there is a match in the
directory ....if a match exists then compare the number of matches (taking a counter/something) and check which is older with system date ....
Once that is identified we need to move the older 1 out

(in reply to abhinav75)
 
 
Post #: 4
 
 Re: comparing file names, etc - 5/10/2005 12:22:03 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
So, you are not looking at comparing the full file name but a prefix and extension to the file? i.e. check for all files that start with xyz and end in dat.

(in reply to abhinav75)
 
 
Post #: 5
 
 Re: comparing file names, etc - 5/10/2005 1:26:49 AM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
comparing the full name .... whr xyz= abc but date would vary hence we need to first compare the text part of the file name ....if a match exists then go ahead and compare the date of the
file. It is on the basis of the date that we sort out the matter of moving the files.

(in reply to abhinav75)
 
 
Post #: 6
 
 Re: comparing file names, etc - 5/10/2005 8:02:00 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
Seriously, I have no idea what you want to do. Could you explain the REASONS behind why you want to do what you want ? Perhaps there is an alternative method.

(in reply to abhinav75)
 
 
Post #: 7
 
 Re: comparing file names, etc - 5/10/2005 4:33:58 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
I have 2 files coming from a server in my folder .....now they come at
differrnt instances on different dates.....
Hence when I start a DTS packages to fetch my data it doesn't fetch from the latest file ...hence I need to move this file out of
this directory so that when the loading starts I get the latest file only ...and hence this logic is needed.

I hope that makes it clear

(in reply to abhinav75)
 
 
Post #: 8
 
 Re: comparing file names, etc - 5/11/2005 8:13:41 AM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
For the file named "xyz040605.dat", which portion is the year, month, and day ?

and is xyz*.dat the only file(s) that you need to determine whether there are duplicates or you could have others eg:

abc<date>.dat
asd<date>.dat

(in reply to abhinav75)
 
 
Post #: 9
 
 Re: comparing file names, etc - 5/11/2005 4:28:59 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
the format is immaterial...
let us take it to be of ddmmyy format..
now what to do?

and yes, all files would have the same prefix,
like abc020202.dat, abc020203.dat, etc.... (these r just examples)

(in reply to abhinav75)
 
 
Post #: 10
 
 Re: comparing file names, etc - 5/11/2005 5:40:27 PM   
  token

 

Posts: 1917
Score: 0
Joined: 1/14/2005
From:
Status: offline
I understand they have the same prefix; however, what I was asking is that how many "sets" of these files are we talking about here ? Do you have ONLY one set, that is, ABC*.dat that you want to check ? or are there multiple sets, such as abc*.dat *AND* xyz*.dat. And you need to determine the latest file from both sets eg:

abc01012004.dat
abc02022004.dat
...
...
xyz01012004.dat
xyz02022004.dat

In the example above, the script can't just focus on abc*.dat because there MIGHT be other files that need to be cleaned up *besides* the files with "abc" prefix.

If the prefix are always "abc" and it is the ONLY prefix that we need to concnern ourselves with, it is a much simpler task. One more thing, MUST you use the <date> within the filename to determiine the latest file or could you use the ACTUAL timestamp of the file for this process ?

(in reply to abhinav75)
 
 
Post #: 11
 
 Re: comparing file names, etc - 5/11/2005 8:07:06 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
the date is part of the filename ....we cant use the timestamp as the file existg in the directory will have the date in the filename.
There are going to be multiple sets ...i.e. a set of abc<date>.dat files

Set of abc%<date>.dat files etc ....so we need to check for them also.

(in reply to abhinav75)
 
 
Post #: 12
 
 Re: comparing file names, etc - 5/12/2005 5:24:08 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
is there no way out??
someone please to help, this is extremely urgent

(in reply to abhinav75)
 
 
Post #: 13
 
 Re: comparing file names, etc - 5/13/2005 5:21:54 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
abhinav75, maybe you can start in this way.

' Description
' Returns a list of all the files whose name beings with a tilde (~).
' This script runs only under Windows XP or Windows .NET Server.

' Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_DataFile where FileName Like '%~%'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next

If you change the %~% in the prefixpart of the filenames to compare,
then you should get your result, I think.

Good luck.

< Message edited by didorno -- 7/20/2005 7:12:14 AM >

(in reply to abhinav75)
 
 
Post #: 14
 
 Re: comparing file names, etc - 5/13/2005 8:50:27 PM   
  abhinav75

 

Posts: 8
Score: 0
Joined: 5/8/2005
From: India
Status: offline
we need to run it as a function in a DTS package and not as a WMI functionality ..
thats where the problem is!

(in reply to abhinav75)
 
 
Post #: 15
 
 Re: comparing file names, etc - 5/14/2005 7:54:45 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
quote:
abhinav75 Posted - 05/14/2005 : 02:50:27 AM we need to run it as a function in a DTS package and not as a WMI functionality ..
thats where the problem is!

I don't know what DTS means.
You need a DTS forum instead of VBScript Forum.

(in reply to abhinav75)
 
 
Post #: 16
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> comparing file names, etc Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts