Batch/script file - compare file na

March 23, 2009 at 23:40:46
Specs: Windows XP-SP3
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

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.

See More: Batch/script file - compare file na

Report •

March 24, 2009 at 00:00:01
if "ABC" is what you want to match, how come BCDEF.txt, BCDGHAW.txt is also what you want?

Report •

March 24, 2009 at 02:10:22
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.


Report •

March 24, 2009 at 02:17:03
**sniff, sniff*** smell like homework...
anyway, this looks like the kind of job for batch to handle.


with createobject("scripting.filesystemobject")
	if not .folderexists(dest) then .createfolder(dest)
	for each f in .getfolder(src).files
		.copyfile src & left(,3) & "*", dest
		exit for
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.

both of the above not working :(

Report •

Related Solutions

March 24, 2009 at 07:31:49
reno: both of the above not working
That's 'cause .Item is looking for a string, not a number.
With CreateObject("Scripting.FileSystemObject").GetFolder(".")
  WScript.Echo .Files("ohmygodimafile")
End With

Report •

March 24, 2009 at 21:40:41
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.

Report •

Ask Question