Calling all scripting experts.... HELP!!!!!

Caporegime
Joined
28 Feb 2004
Posts
74,822
Hi all,
I have a little challenge for you all that should be pretty easy to sort out if you have even a modicum of scripting knowledge, which sadly I do not, I really must get round to learning someday.

I have a whole bunch of files, approx 2500 so far, but increasing daily, that are all of the format

B1000.hdr, B1000.log, B1000.plg, B1000.alg, B1000.slg, B1000.hlg, B1000.clg, B1000.eot, B1000.fin.

then the next bunch are named B1001...., then B1002....., etc, etc, you get the picture I hope.

These files need moving from one folder, where they are all jumbled up together, in to another set of folders that are more organised.

The new folders are in a set of directories named as
B1000 - B1999
B2000 - B2999
etc etc

In each directory I need the folders named
B1000
B1001
B1002
etc etc

Then the files with extension names .log, .plg, .alg, .slg, .hdr, need copying into their appropriate folder. The other files can be left in the original folder.

Up to now I have been creating new folders manually and copying and pasting the necessary files, as you can imagine, this is somewhat tedious and mind numbingly boring.
I am sure a little script or batch file could make the job so much easier and faster, but I do not have a clue wher to start, so I am calling on the vast knowledge and expertise of OCUK to help stop my fingers wearing away to nothing.
Obviously if there is any more info needed just ask.
Thank you, and sorry for the length of the post.
 
Is this on Windows or something UNIX(like) that has a sensible scripting language?

First comment would be to change the names of the first level of paths from "B1000-B1999" to simply "B1000" or the like, that way you can generate the target path name as a simple substring with a fixed string appended to it rather than having to calculate the part after the dash.
 
Is this on Windows or something UNIX(like) that has a sensible scripting language?

First comment would be to change the names of the first level of paths from "B1000-B1999" to simply "B1000" or the like, that way you can generate the target path name as a simple substring with a fixed string appended to it rather than having to calculate the part after the dash.


It is in windows XP, I'm afraid, just be gratefull as we only changed from Windows 2000 in june, and the machine that the files originally come from is still running NT4, but we copy them to CD and transfer them to the main system for backup which is where this organising comes in.

I do not have control over the way the level of paths have been set up,
I have only recently taken over this particular task here at work, and it is a case of "this is the way we do it, we have always done it this way, just get on with it".

I'm afraid it is a very dinosaur type of company, they do not like change in any way, and that makes it very hard to do anything economically.


Edit:


I'm beginning to get the feeling this may not be as easy as I thought, sorry :o
 
Last edited:
It's not too bad, I'll have a look into knocking something up for you when I get a spare 5 minutes at work, unless anyone else wants to jump in first of course.

Bear in mind though, doing this in windows means you'll have to use the FileSystemObject which working on 22,500 files, and 2,503 folders will take some time to process when you run it :)
 
It's not too bad, I'll have a look into knocking something up for you when I get a spare 5 minutes at work, unless anyone else wants to jump in first of course.

Bear in mind though, doing this in windows means you'll have to use the FileSystemObject which working on 22,500 files, and 2,503 folders will take some time to process when you run it :)


Cheers, that would be great.
I get used to things taking time to process, imagine sitting waiting for a high speed movie file averaging 2.5-4 gig in size, getting converted into an AVI, it can take anything up to a couple of hours on our best machine, a dual core with two gig of ram, most machines are P4's with 512Mb maybe 1gig of ram.
 
You're not completely out of options, there is an MS scripting add on which is much better than plain batch files or you could stick Cygwin on there and just do it using UNIX style shell scripts. You might be able to get away with batch scripting if you can get the find command to pull the first part of the filenames out for you but it's not going to be pretty.

Thinking about it there might be a simpler way of doing this. What you need to generate is a set of move commands and a set of mkdir commands. For the sake of simplicity just assume that you'll get sequential numbers and if you end up with empty directories then that's not going to hurt anyone. So generate a set of mkdir commands in a text editor or use Excel to generate an incrementing list of numbers and turn that into the commands so that you end up with a file full of:

Code:
mkdir B1000-B1999\B1000
mkdir B1000-B1999\B1001
....

Then all you need is a script full of move commands generated in a similar way
Code:
mv B1000.* B1000-B1999\B1000
mv B1001.* B1000-B1999\B1001
....

It's ugly and you'll need to either generate a file with more commands than you need or keep recreating the commands as you generate more files but it'll work.
 
Hi Entai,

I'm really sorry, I'm not going to be able to sort something out for you until most likely next week as I'm chocka in the office this week.

Have a friendly bump, to see if someone else can help you in the meantime :)
 
Cheers Spunkey, no real rush if you can do something it would be great. :)

I have tried a very rough, nasty, ugly, batch file along the lines of what rpstewart was talking about, it kind of does the job, but it needs a fair bit of tidying up afterwards, and obviously a lot of re-writing for the next batch of files etc.
 
Have a go with this.

Recommend you take a backup first or something though :)

1. Create a text file
2. Copy all the text in
3. Change where it says ****ENTER FOLDER PATH HERE IN QUOTES**** to be the folder that contains the files.
4. Rename it to 'something.vbs'.
5. Place the text file into the folder that contains the files.
6. Almost needless to say but just double click the file to run.

Code:

Dim objfso
Dim folder
Dim files
Dim leftstr
Dim rtfolder
Dim currentpath
Dim filenamelen
Dim subfolder
Dim location
Dim filepath

Set objfso = CreateObject("Scripting.FileSystemObject")

currentpath = objfso.getAbsolutePathName("")

Set folder = objfso.GetFolder("****ENTER FOLDER PATH HERE IN QUOTES****")

Set files = folder.Files

for each objFile in files

filename = objFile.Name

leftstr = left(filename, 2)
filenamelen = len(filename)
subfolder = left(filename, filenamelen - 4)

if left(filename, 1) = "B" then

rtfolder = leftstr & "000 - " & leftstr & "999"

location = currentpath & "\" & rtfolder & "\" & subfolder & "\"
filepath = location & filename

if objfso.folderexists(rtfolder) = false then
objfso.createfolder(rtfolder)
end if

if objfso.folderexists(location) = false then
objfso.createfolder(location)
end if

if objfso.fileexists(filepath) = true then
objfso.deletefile(filepath)
end if

objfso.movefile filename, location

End if

next

Set objFSO = nothing
Set folder = nothing
Set files = nothing
 
Last edited:
I have just updated it a little

It should create the root and subfolders for any combination of files now almost as long as they start with "B"

Bonus of this is that it doesn't waste time with files that are already filed away like :)
 
Last edited:
Back
Top Bottom