Solved

Windows Batch filename contains...

Posted on 2008-06-11
9
461 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 4

Author Comment

by:superblades
Comment Utility
no joy
same problem

Regards

Superblades
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 67

Expert Comment

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

Author Comment

by:superblades
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks spot on!
0
 
LVL 67

Expert Comment

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

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 …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now