Folder Creation

  • Thread starter Thread starter Jamie
  • Start date Start date
J

Jamie

Hi There,

I'm not sure if this is the correct place to ask this question but here
goes.

I have a folder with over 2000 files in it.

All the files are names in the format

location_uniqueRefNumber

What I want is to have a folder for each location and have all the files
with the same location in that folder.

I can manually go through and create hundreds of folders then move each file
tot he correct one.

Is there some automated way to create the folder and put the files in the
correct ones? Such as create a folder for each location and putting all the
same location files then in that folder.

hope this makes sense.

Thanks

--

Jamie Allison
Sheffield Hallam University
Software Engineering
Final Year
 
How specific?

the file name is location which is alphanumberic text followed by an
underscore then followed by a numbered unique identifier then the file
extensions. Some are .jpg some.doc and others .txt.

So that is

Location_UnqueIdentifier.extension

Thanks

"David Candy" <.> wrote in message
You neewd to be specific about the file names.
 
for %A in (*.*) do (For /f "tokens=1 delims=_ usebackq" %B in ('%A') Do Md %B)

Will attempt to create a folder. It will fail on second and subsequent attempt but who cares.

I'm not prepared to spend anymore time as you refused to supply names.

Type For in help
 
I didn't realise you wanted names.

Some examples are.

Hartlepool_0001.jpg
Hartlepool_0002.jpg
Hartlepool_0003.jpg
Hartlepool_0004.jpg
Hartlepool_0005.txt
Hartlepool_0006.doc
Sheffield_0001.jpg
Sheffield_0002.jpg
Sheffield_0003.jpg
Sheffield_0004.jpg
Sheffield_0005.txt
Sheffield_0006.txt
Sheffield_0007.txt
Sheffield_0008.txt
London_0001.doc
London_0002.txt
London_0003.jpg
London_0004.jpg
London_0005.jpg
London_0006.jpg

Sorry I didn't realise you meant full names I thought that the example would
be enough.

Thanks for your help so far.

Regards


"David Candy" <.> wrote in message
for %A in (*.*) do (For /f "tokens=1 delims=_ usebackq" %B in ('%A') Do Md
%B)

Will attempt to create a folder. It will fail on second and subsequent
attempt but who cares.

I'm not prepared to spend anymore time as you refused to supply names.

Type For in help
 
Also would the above code you gave go into a batch file in the folder which
contains all of the files.

I'm on windows XP and have put that code into a batch file but when I double
click it flashes on the screen and then off quickly and doesn't seem to do
anything.

Thanks Again

"David Candy" <.> wrote in message
for %A in (*.*) do (For /f "tokens=1 delims=_ usebackq" %B in ('%A') Do Md
%B)

Will attempt to create a folder. It will fail on second and subsequent
attempt but who cares.

I'm not prepared to spend anymore time as you refused to supply names.

Type For in help
 
If they were fixed length names (at least the first part) it's a lot easier. They don't appear to be (that's understatement which is how my culture talks).

The first line I posted creates the folders. Type cmd in Start Run, then type

cd <path to folder>

then

for %A in (*.*) do (For /f "tokens=1 usebackq delims=_" %B in ('%A') Do Md %B)

then

for %A in (*.*) do (For /f "tokens=1 delims=_ usebackq" %B in ('%A') Do Copy "%A" ".\%B")

Note it will fail on files that aren't in the format you specified. You should test first on a small sample of the files in another folder (like ..

Hartlepool_0005.txt
Hartlepool_0006.doc
Sheffield_0001.jpg
Sheffield_0002.jpg
)
 
In a batch one needs to use two % signs

For %%A etc

If you put it in that folder it will try to create a folder of that name, and if the bat name doesn't have an underscore it will try to create a folder with the same name and extension of the file and fail (as a file with that name already exists and folders are files that are treated specially). Not that this really matters.

Single % vs double % is about the only difference between batch and typing. All % need to be doubled in a batch file.
 
Thank you,

That helps a lot. I'm sorry I didn't provide enough file information at
first.

One slight problem with it is that some of the file name have a space in the
on the beginning part such as

North Yorkshire_0001.jpg
or
West Midlands_0001.jpg

For these it seems to want to create lots of folders one for North one for
Yorkshire, one for West and one for midlands.

Any ideas?

Thanks

"David Candy" <.> wrote in message
If they were fixed length names (at least the first part) it's a lot easier.
They don't appear to be (that's understatement which is how my culture
talks).

The first line I posted creates the folders. Type cmd in Start Run, then
type

cd <path to folder>

then

for %A in (*.*) do (For /f "tokens=1 usebackq delims=_" %B in ('%A') Do Md
%B)

then

for %A in (*.*) do (For /f "tokens=1 delims=_ usebackq" %B in ('%A') Do Copy
"%A" ".\%B")

Note it will fail on files that aren't in the format you specified. You
should test first on a small sample of the files in another folder (like .

Hartlepool_0005.txt
Hartlepool_0006.doc
Sheffield_0001.jpg
Sheffield_0002.jpg
)


----------------------------------------------------------------------------------------
WARNIE IS KING (dunno why the let the poms etc in the team - 5 australian
players could make a team)

In the tsunami benefit match,
Asia is 4/127 chasing RestOfTheWorld's 345 after 23.2 overs. Kerry Packer
donated $3 million.
 
for %A in (*.*) do (For /f "tokens=1 usebackq delims=_" %B in ('%A') Do Md %B)

Is slightly different to the first line I wrote

also try

for %A in (*.*) do (For /f "tokens=1 usebackq delims=_" %B in ('%A') Do Md "%B")

This is one reason full details are required so issues with spaces (and they make a big difference) can be addressed without 40 questions and answers.

I considered 3 seperate programming languages of which batch is the least flexible (but easist for you). So I did this thinking I was probably wasting my time.
 
Thanks a million.

This one works great now.

Saved me a huge amount of time.

Regards

"David Candy" <.> wrote in message
for %A in (*.*) do (For /f "tokens=1 usebackq delims=_" %B in ('%A') Do Md
%B)

Is slightly different to the first line I wrote

also try

for %A in (*.*) do (For /f "tokens=1 usebackq delims=_" %B in ('%A') Do Md
"%B")

This is one reason full details are required so issues with spaces (and they
make a big difference) can be addressed without 40 questions and answers.

I considered 3 seperate programming languages of which batch is the least
flexible (but easist for you). So I did this thinking I was probably wasting
my time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top