Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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:\matchedDATA:
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 fileThe 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.

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

**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 :(

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

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.

![]() |
![]() |
![]() |

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