?
Solved

Windows Batch filename contains...

Posted on 2008-06-11
9
Medium Priority
?
475 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
Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

 
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 2000 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

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month11 days, 15 hours left to enroll

752 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