Solved

Vbs script to create Directories and move files to directory

Posted on 2011-02-26
10
342 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
[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
  • 6
  • 4
10 Comments
 
LVL 55

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 55

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Closing Comment

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

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 55

Expert Comment

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

~bp
0
 
LVL 55

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 55

Expert Comment

by:Bill Prew
ID: 34989239
Welcome.

~bp
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

687 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