Solved

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

Posted on 2014-01-22
6
512 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 54

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 54

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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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 54

Expert Comment

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

~bp
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
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 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…

732 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