MS DOS
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   Web Development Archives FAQs MS DOS

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Web Development Archives Sponsor:
  #1  
Old April 24th, 2008, 02:45 AM
moe_w90 moe_w90 is offline
Registered User
Dev Archives Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 moe_w90 User rank is Just a Lowly Private (1 - 20 Reputation Level)  
Time spent in forums: 11 m 26 sec
Reputation Power: 0
Copy files based to different directories based on certain characters in file name

Hi,

I have thousands of files with names in format filename_str1_str2.dat where str1 is some string occurnace in file name.
I want to write a dos batch that can read str1 from name of file and based on value copies the file to one of several directories. I cann't find a way to strip str1 from file name. The batch should be able to iterate through all files in directory and copy to destination based on str1. Any help please ?

Thanks

Moe

Reply With Quote
  #2  
Old May 2nd, 2008, 08:56 PM
wwjdcsk wwjdcsk is offline
Registered User
Dev Archives Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 6 wwjdcsk User rank is Just a Lowly Private (1 - 20 Reputation Level)  
Time spent in forums: 1 h 32 m 50 sec
Reputation Power: 0
You can use a FOR loop to parse a variable into tokens. See the for command help by typing "for /?" into your command line.

You can write a batch file like this:

Code:
set FILE=filename_str1_str2.dat

for /f "tokens=1-3 delims=_" %%I in ("%FILE%") do (
   echo %%I
   echo %%J
   echo %%K
   echo copy %FILE% %%J
)


Output:
Code:
filename
str1
str2.dat
copy filename_str1_str2.dat str1


you can remove the 'echo' on the 'echo copy' line to get your copy functionality

Reply With Quote
Reply

Viewing: Web Development Archives FAQs MS DOS > Copy files based to different directories based on certain characters in file name


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway