Solved

Windows Batch filename contains...

Posted on 2008-06-11
9
473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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