Solved

Vbs script to create Directories and move files to directory

Posted on 2011-02-26
10
337 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 51

Expert Comment

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

~bp
0
 
LVL 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
any thing is acceptable  :)
0
 

Author Closing Comment

by:armstrongnt
Comment Utility
Thank you....very much
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Very welcome, glad to help, thanks.

~bp
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:armstrongnt
Comment Utility
+---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 51

Expert Comment

by:Bill Prew
Comment Utility
Okay, that's doable, just a minute...

~bp
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
Worked like a charm Thank you very much.. :)
0
 
LVL 51

Expert Comment

by:Bill Prew
Comment Utility
Welcome.

~bp
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

15 Experts available now in Live!

Get 1:1 Help Now