?
Solved

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

Posted on 2014-01-22
6
Medium Priority
?
517 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 56

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 56

Accepted Solution

by:
Bill Prew earned 2000 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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 56

Expert Comment

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

~bp
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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 …
In a recent article here at Experts Exchange (http://www.experts-exchange.com/articles/18880/PaperPort-14-in-Windows-10-A-First-Look.html), I discussed my nine-month sandbox testing of the Windows 10 Technical Preview, specifically with respect to r…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

777 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