Computer Hope

Microsoft => Microsoft DOS => Topic started by: hrm on April 29, 2009, 10:27:01 AM

Title: Read Characters from filename and move the file to a subfolder
Post by: hrm on April 29, 2009, 10:27:01 AM
Hi,
I need to read a filename and based on some characters, decide to move the file in appropriate folders. Here is an example:

gibberish_Water_Cloud.abc
gibb_Water_Sky.abc
moregibb_Air_Sky.abc
stillmorgib_Air_Cloud.abc

I need to move these into following four folders that already exist:
Water_Cloud
Water_Sky
Air_Sky
Air_Cloud

Any help will be appreciated.
Thanks

Title: Re: Read Characters from filename and move the file to a subfolder
Post by: macdad- on April 29, 2009, 11:21:37 AM
This should help, make sure you put it in the same folder as the abc files.

Code: [Select]
@echo off
for /f %%a in (*Water_Cloud.abc) do move %%a Water_Cloud\%%a
for /f %%a in (*Water_Sky.abc) do move %%a Water_Sky\%%a
for /f %%a in (*Air_Sky.abc) do move %%a Air_Sky\%%a
for /f %%a in (*Air_Cloud.abc) do move %%a Air_Cloud\%%a

Hope this helps
,Nick(macdad-)
Title: Re: Read Characters from filename and move the file to a subfolder
Post by: gh0std0g74 on April 29, 2009, 07:27:49 PM
no need to use the for loop.
Code: [Select]
move *Water_Sky Water_Sky
Title: Re: Read Characters from filename and move the file to a subfolder
Post by: macdad- on April 30, 2009, 06:21:14 AM
Oh well...either works
Title: Re: Read Characters from filename and move the file to a subfolder
Post by: gh0std0g74 on April 30, 2009, 07:36:12 AM
yes, either works. but ..............