Solved

Vbs script to create Directories and move files to directory

Posted on 2011-02-26
10
339 Views
Last Modified: 2012-05-11
I have bunch of files
0010.txt
001.txt
asd0.txt
0030.txt
0040.txt
0050.txt
vbs script  should create folder structure like this for for every individual file
for 0010.txt
0010 \components
         \notes
         \version
         \workshop\0010_workshop_0001.txt
0010.txt should be copied to 0010 \workshop\ and should be renamed 0010_workshop_0001.txt

the complete path of the file should be  *\0010 \workshop\0010_workshop_0001.txt

IMPORTANT NOTE * represents watever the folder path

one more example fir 0030

0030 \components
         \notes
         \notes
         \workshop\0030_workshop_0001.txt
0010.txt should be copied to 0030 \workshop\ and should be renamed 0030_workshop_0001.txt

the complete path of the file should be  *\0030 workshop\0030_workshop_0001.txt


"components" "notes" "version" Folders are just emply folders which would be used latter on
0
Comment
Question by:armstrongnt
  • 6
  • 4
10 Comments
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34988857
This could be done quite easily in a BAT Script, would that be acceptable, or do you require VBS?

~bp
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 34988923
If you wanted to go the BAT rout this should do it.

@echo off
set BaseDir=c:\Temp\EE26850102
for %%A in ("%BaseDir%\*.txt") do (
  md %BaseDir%\%%~nA\components
  md %BaseDir%\%%~nA\notes
  md %BaseDir%\%%~nA\version
  md %BaseDir%\%%~nA\workshop
  copy "%%A" "%BaseDir%\%%~nA\workshop\%%~nA_workshop_0001.txt"
)

Open in new window


This resulted in the following folder and file structure being created:

+---001
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           001_workshop_0001.txt
¦
+---0010
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0010_workshop_0001.txt
¦
+---0030
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0030_workshop_0001.txt
¦
+---0040
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0040_workshop_0001.txt
¦
+---0050
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0050_workshop_0001.txt
¦
+---asd0
    +---components
    +---notes
    +---version
    +---workshop
            asd0_workshop_0001.txt

Open in new window

~bp
0
 

Author Comment

by:armstrongnt
ID: 34988928
any thing is acceptable  :)
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

Author Closing Comment

by:armstrongnt
ID: 34988973
Thank you....very much
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34988980
Very welcome, glad to help, thanks.

~bp
0
 

Author Comment

by:armstrongnt
ID: 34989007
+---001
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           001_workshop_0001.txt
            001_workshop_0002.txt
                  001_workshop_0003.txt
                  001_workshop_0004.txt
                  001_workshop_0005.txt
¦
+---0010
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0010_workshop_0001.txt
¦           0010_workshop_0002.txt
¦           0010_workshop_0003.txt
            0010_workshop_0004.txt
            0010_workshop_0005.txt
            0010_workshop_0006.txt
            0010_workshop_0007.txt
            0010_workshop_0008.txt
            0010_workshop_0009.txt
            0010_workshop_0010.txt
            0010_workshop_0011.txt
¦
+---0030
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0030_workshop_0001.txt
            0030_workshop_0002.txt
                  
                  

                  NOW I need a bat file That can copy the last version of the 001.txt(i.e  001_workshop_0005.txt) to its main folder (i.e 001 folder ) and name it has 001_Final.txt
                  
                  The Result should be
+---001
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           001_workshop_0001.txt
            001_workshop_0002.txt
                  001_workshop_0003.txt
                  001_workshop_0004.txt
                  001_workshop_0005.txt
001_Final.txt (this file should be  a copy of 001_workshop_0005.txt )
¦
+---0010
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0010_workshop_0001.txt
¦           0010_workshop_0002.txt
¦           0010_workshop_0003.txt
            0010_workshop_0004.txt
            0010_workshop_0005.txt
            0010_workshop_0006.txt
            0010_workshop_0007.txt
            0010_workshop_0008.txt
            0010_workshop_0009.txt
            0010_workshop_0010.txt
            0010_workshop_0011.txt
0010_Final.txt this file should be  a copy of 0010_workshop_0011.txt )
¦
+---0030
¦   +---components
¦   +---notes
¦   +---version
¦   +---workshop
¦           0030_workshop_0001.txt
            0030_workshop_0002.txt
0030_Final.txt this file should be  a copy of 0030_workshop_0002.txt )
                  
                  
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34989029
Okay, that's doable, just a minute...

~bp
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34989123
I think this should do what you asked for.

@echo off
setlocal EnableDelayedExpansion
set BaseDir=c:\Temp\EE26850102
for /D %%A in ("%BaseDir%\*") do (
  if exist "%%A\workshop\" (
    for /F "tokens=*" %%B in ('dir /b /a-d /on "%%A\workshop\*.txt"') do set LastFile=%%B
    copy "%%A\workshop\!LastFile!" "%%A\workshop\%%~nA_Final.txt"
  )
)

Open in new window

~bp
0
 

Author Comment

by:armstrongnt
ID: 34989224
Worked like a charm Thank you very much.. :)
0
 
LVL 53

Expert Comment

by:Bill Prew
ID: 34989239
Welcome.

~bp
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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