Solved

Dos bat Script to loop through files with a -0.7z suffix.

Posted on 2014-01-22
6
515 Views
Last Modified: 2014-01-22
The only difference between this script and this one is that the one works with a folder name and the one I need now needs to work with a file name.

So far the script looks like this. I know it cannot be completely wrong.

::@echo off
:DATAAVAILABILITYCHECK

setlocal enabledelayedexpansion
IF EXIST D:\DATA\ SET DataFile=D:\DATA\
IF EXIST E:\DATA\ SET DataFile=E:\DATA\
IF EXIST F:\DATA\ SET DataFile=F:\DATA\
IF EXIST G:\DATA\ SET DataFile=G:\DATA\
IF EXIST H:\DATA\ SET DataFile=H:\DATA\


setlocal enabledelayedexpansion
for /f %%a in ("%DataFile%") do (
	set FolderName=%%~nxa
	if /i "!FolderName:~-5!"=="-0.7z" (
		set ProcessFolder=%%~a
		goto :DATASETSTART
	)
)
CLS
ECHO NO DATA SETS DETECTED...
PAUSE
CLS
GOTO :DATAAVAILABILITYCHECK


:DATASETSTART
ECHO FILE DETECTED AS %ProcessFolder%...
::SCRIPT WILL BE IN HERE AND PERFORM ACTIONS WITH %ProcessFolder%
::ONCE ACTIONS IS FINISHED THE SUFFIX WILL BE CHANGED FROM "-0" to "-1"
::WHEN THE SCRIPT IS FINISHED IT WILL GOTO :DATAAVAILABILITYCHECK

Open in new window

0
Comment
Question by:Rebel_no_1
[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
  • 3
  • 3
6 Comments
 
LVL 55

Expert Comment

by:Bill Prew
ID: 39799752
So, are there folders under the DATA directory, or do you just want to process any matching files within that one folder?

~bp
0
 

Author Comment

by:Rebel_no_1
ID: 39799770
There is no folders inside the DATA directory. Only files with a file name similar to these:
ECN-0601-VRK__2014-01-22__20h43-0.7z
ECN-0604-VRK__2014-01-01__10h43-0.7z
ECN-0702-VRK__2014-01-22__10h43-0.7z
ECN-0904-VRK__2014-01-31__10h43-0.7z

The idea is to process them one by one. After they are processed the suffix will change from "-0" to "-1".

Therefore, if the above four files have been processed their names will be:
ECN-0601-VRK__2014-01-22__20h43-1.7z
ECN-0604-VRK__2014-01-01__10h43-1.7z
ECN-0702-VRK__2014-01-22__10h43-1.7z
ECN-0904-VRK__2014-01-31__10h43-1.7z

Hope this helps to clarify the scripts intended operation.
0
 
LVL 55

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 39799925
I think this should be pretty close to what you need, let me know what questions you have.

@echo off
setlocal EnableDelayedExpansion

:DataAvailabilityCheck

set DataFile=
for %%A in (D,E,F,G,H) do (
  if exist %%A:\DATA\ set DataFile=%%A:\DATA\
)

if "%DataFile%" EQU "" (
    REM *** NOT SURE WHAT YOU WANT TO DO UNDER THIS CONDITION ***
    echo No data file folder could be located
    exit /b
)

set FileCount=0
for %%A in ("%DataFile%*-0.7z") do (
    set /a FileCount+=1
    set FileName=%%~nxA
    echo Processing file: "%%~A"
    REM *** DO ANY PROCESSING HERE ***
    ren "%%~A" "!FileName:-0.7z=-1.7z!"
)

cls
Processed [%FileCount%] files.
goto :DataAvailabilityCheck

Open in new window

~bp
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:Rebel_no_1
ID: 39800047
I think it is exactly what we need. It works perfectly. Thanks allot Bill.
0
 

Author Closing Comment

by:Rebel_no_1
ID: 39800053
The solution works exactly in the expected manner. Bill's a champ!
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 39800588
Great, glad that was useful, and thanks for the great feedback!

~bp
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
#Citrix #POC #XenDesktop #vCenter #VMware #ESX
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

688 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