Computing.Net > Forums > Programming > Batch/script file - compare file na

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch/script file - compare file na

Reply to Message Icon

Name: Chat Patta
Date: March 23, 2009 at 23:40:46 Pacific
OS: Windows XP-SP3
Subcategory: Batch
Comment:

Hi Guru (male/female):

Need help with script files (vbs/bat) to be run on XP. Want to compare the first 'X' characters of the file name with the rest of the file names in the same directory. X, paths for source directory and path to the matched directory will be entered by the user. So no particular string is being input, but the script itself reads the firs file's name, takes the first X characters and form a string to be compared.

All matching files will be moved to matched directory.

Please note there can be any number matches. Like there can be two, three or n files with the same X number of characters as file name.

I would be grateful if someone can help me write this or point to an application which can perform this particular action, somebody suggested filemonkey/filemonk, i could not figure out how to compare a partial set of characters which are position sesitive in file names.

Here is an example:

To be entered by user:
string length to compare X=3
source directory path = c:\temp1
matched directory path = c:\matched

DATA:
Files in c:\temp1 =
ABCAAA.txt, ABCBBBBB.txt, ABCD.txt, ABDAAA.txt, BCDEF.txt, BCDGHAW.txt, FGACD.txt and BABC.txt


After running the script/batch file

The first file is ABCAAA.txt, so the script take "ABC" from the files name and search the rest of the files first 3 characters with "ABC". Once match found it transfers the all the matched files.

files transfered since comparison ("ABC") was found, c:\matched = ABCAAA.txt, ABCBBBBB.txt, ABCD.txt, BCDEF.txt, BCDGHAW.txt

files left as no comparison found, c:\temp1 = ABDAAA.txt, FGACD.txt and BABC.txt
Note: Because the position (i.e. start of the file name) is important so BABC.txt was not a matched file even though it has ABC in its name.

Much obliged for any help in this regards

P.S. this is not my homework/assignment, i want to use this to sort the mp3 files. All my native (Hindi music files) file names are in English, and many variations of English characters are used to pronounce the non-english word of Hindi. Number of words translated as title varies too, hence almost no two file names are same, the file size differ too (quality wise)..... so the only way for me is to search limited characters between file names.



Sponsored Link
Ads by Google

Response Number 1
Name: ghostdog
Date: March 24, 2009 at 00:00:01 Pacific
Reply:

if "ABC" is what you want to match, how come BCDEF.txt, BCDGHAW.txt is also what you want?


0

Response Number 2
Name: Mechanix2Go
Date: March 24, 2009 at 02:10:22 Pacific
Reply:

We can get the number of chars, src and dest like this:

@echo off

set /p src=src?
set /p dest=dest?
set /p N=number of chars?

==========================
Where do we get WHICH N chars to look for?


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 3
Name: reno
Date: March 24, 2009 at 02:17:03 Pacific
Reply:

**sniff, sniff*** smell like homework...
anyway, this looks like the kind of job for batch to handle.

src="c:\temp1\"
dest="c:\matched\"

with createobject("scripting.filesystemobject")
	if not .folderexists(dest) then .createfolder(dest)
	for each f in .getfolder(src).files
		.copyfile src & left(f.name,3) & "*", dest
		exit for
	next
end with

change .copyfile to .movefile for moving file(s).

dang, i couldn't find a way to directly accessing the files collection as in array.
.getfolder(src).files(0).name
.getfolder(src).files.item(0).name

both of the above not working :(


0

Response Number 4
Name: Razor2.3
Date: March 24, 2009 at 07:31:49 Pacific
Reply:

reno: both of the above not working
That's 'cause .Item is looking for a string, not a number.

With CreateObject("Scripting.FileSystemObject").GetFolder(".")
  .CreateTextFile("ohmygodimafile")
  WScript.Echo .Files("ohmygodimafile")
End With


0

Response Number 5
Name: reno
Date: March 24, 2009 at 21:40:41 Pacific
Reply:

thanks razor. i was looking for the filename of first item in collection without enumerating it.

so i need to pass the filename as the key in order to get the name of the file, LOL@microsoft.


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch/script file - compare file na

Batch script for file copy www.computing.net/answers/programming/batch-script-for-file-copy/14874.html

Batch script: Help with FOR file IO www.computing.net/answers/programming/batch-script-help-with-for-file-io/14915.html

batch script to pick thelatest file www.computing.net/answers/programming/batch-script-to-pick-thelatest-file/16427.html