Solved

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

Posted on 2014-01-22
6
503 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
  • 3
  • 3
6 Comments
 
LVL 52

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 52

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

 

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 52

Expert Comment

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

~bp
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
This collection of functions covers all the normal rounding methods of just about any numeric value.
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.

911 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

23 Experts available now in Live!

Get 1:1 Help Now