Solved

Windows Batch filename contains...

Posted on 2008-06-11
9
469 Views
Last Modified: 2010-04-21
The network location may contain upto three zips with the letters NTO, PCN, or BLE in the filename
i need to modify the code below so that when it connects and copys everything from the network location. If the filename contains NTO it puts it into e:\folder\NTO\ if it contains PCN it puts it into e:\folder\PCN if it contains BLE it moves it to BLE etc etc.

then it renames the file to export.zip

then using pzunzip (picozip) it needs to unzip the contents to the current location and rename the file without an extension to 'export' for BLE, PCN and NTO and then delete the contents on the remote share and then remove the network drive.

Previously it was just one zip so the code worked fine however i need to change it now.

any ideas?




i

@Echo Off
del e:\folder\images\*.* /q
NET USE i: \\129.3.10.16\folder /USER:server\username password
XCOPY i:\*.* e:\folder\images\*.* 
FOR %%A IN (e:\bus_lane\images\*.ZIP) DO IF NOT "%%~A"=="e:\folder\images\Export.ZIP" REN %%~A Export.ZIP
pzunzip e:\folder\images\export.zip e:\folder\images\
del i:\*.* /q
NET USE i: /DELETE /Y
cd e:\folder\images\
ren *. export

Open in new window

0
Comment
Question by:superblades
  • 5
  • 4
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 21759010
Something like this should work - remove the ECHO below to make it actually process the files...
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*NTO*') do ECHO move "%%T" e:\folder\NTO
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*PCN*') do ECHO move "%%T" e:\folder\PCN
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*BLE*') do ECHO move "%%T" e:\folder\BLE

Open in new window

0
 
LVL 4

Author Comment

by:superblades
ID: 21759323
I get

'the system cannot find the file specified'
'the system cannot find the file specified'
'the system cannot find the file specified'

?

Its copying them across ok but just not moving them

@Echo Off
del e:\folder\images\*.* /q
NET USE i: \\129.3.10.16\folder /USER:server\username password
XCOPY i:\*.* e:\folder\images\*.*
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*NTO*') do move "%%T" e:\folder\NTO
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*PCN*') do move "%%T" e:\folder\PCN
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*BLE*') do move "%%T" e:\folder\BLE

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 21759411
Think I see it...specify the path as well..

XCOPY i:\*.* e:\folder\images\*.*
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*NTO*') do move "%%~dpnxT" e:\folder\NTO
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*PCN*') do move "%%~dpnxT" e:\folder\PCN
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*BLE*') do move "%%~dpnxT" e:\folder\BLE
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 4

Author Comment

by:superblades
ID: 21759475
no joy
same problem

Regards

Superblades
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 21759561
what was the 'echo' display from my first post?
0
 
LVL 4

Author Comment

by:superblades
ID: 21759652
its looking for e:\folder\file not e:\folder\images\file


move "E:\folder\0530NTO02.zip" e:\folder\NTO
move "E:\folder\0530PCN02.zip" e:\folder\PCN
move "E:\folder\0530BLE02.zip" e:\folder\BLE

Open in new window

0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 21759699
Hmm - that's a bit odd, but you can override it with:

for /f "tokens=*" %%T in ('dir /b e:\folder\images\*NTO*') do move "e:\folder\images\%%T" e:\folder\NTO\
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*PCN*') do move "e:\folder\images\%%T" e:\folder\PCN\
for /f "tokens=*" %%T in ('dir /b e:\folder\images\*BLE*') do move "e:\folder\images\%%T" e:\folder\BLE\
0
 
LVL 4

Author Closing Comment

by:superblades
ID: 31466098
Thanks spot on!
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 21760251
Still...puzzling why the other method wouldn't work, but glad it's sorted. :^)
Thanx for the grade.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question