Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbs script to create folders + subfolders by input foldernames 1

Status
Not open for further replies.

TvdH1981

MIS
Mar 28, 2022
17
NL
Hello,

I am at this for a couple off days and totally new at this. This is what I got so far from google and youtube. It works and creates the folders, but I need the folders names from the inputboxes. I cant seem to get it work. Can somebody please help me. And also add some script for files that allrady exist so it looks at the date. just as you would add in a batch script \s \d.

I want to make this work

regards Tim



Option Explicit

DIM fSO

DIM foldername1
DIM foldername2
DIM foldername3

foldername1=INPUTBOX("KLANTNAAM")
foldername2=INPUTBOX("FENDERTYPE")
foldername3=INPUTBOX("ORDERNUMMER")

SET FSO=CreateObject("Scripting.FileSystemObject")

FSO.CREATEFOLDER("C:\Users\USERNAME\Desktop\TEST1\")
FSO.CREATEFOLDER("C:\Users\USERNAME\Desktop\TEST1\foldername1\")
FSO.CREATEFOLDER("C:\Users\USERNAME\Desktop\TEST1\foldername1\foldername2\")
FSO.CREATEFOLDER("C:\Users\USERNAME\Desktop\TEST1\foldername1\foldername2\foldername3\")

FSO.COPYFOLDER "C:\Users\USERNAME\Downloads","C:\Users\USERNAME\Desktop\TEST1\foldername1\foldername2\foldername3\"
 
HTA - this technology, which is actually already outdated, should definitely run on Windows 7, because in Windows 7 Internet Explorer was still the default web browser and with it the program mshta.exe, which runs the HTA applications, should be there.
 
If it is a company laptop, the use of HTA may have been disabled, as they are seen as a big security risk.
 
Knipsel_r3hkfk.jpg


not a valid win32


its my own laptop. But if I cant run it on my work than the whole point of usage is gone :)
 
Well maybe I have to go to an excel sheet and great folders
 
Ok thanks it works now. But I think this is way to much work to fill in all the veriables.

Can you change fendertype and ordernumber back to input boxes and leave the custommer as is? Is it possible to refer to a excel sheet with custommers?
 
TvdH1981 said:
Can you change fendertype and ordernumber back to input boxes and leave the custommer as is?
Yes, i have done it

2022-04-01_09h18_15_kkovcz.png


Here is the source code:

TvdH1981.hta
Code:
[COLOR=#008080]<[/color][COLOR=#008080]html[/color][COLOR=#008080]>[/color]
  [COLOR=#008080]<[/color][COLOR=#008080]head[/color][COLOR=#008080]>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]title[/color][COLOR=#008080]>[/color]TvdH1981[COLOR=#008080]</title>[/color]
    [COLOR=#008080]<[/color][COLOR=#6a5acd]HTA[/color][COLOR=#0000ff]:[/color][COLOR=#008080]APPLICATION[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]ID[/b][/color]=[COLOR=#ff00ff]"hta:ListBoxApp"[/color][COLOR=#008080] [/color]
[COLOR=#008080]    [/color][COLOR=#2e8b57][b]APPLICATIONNAME[/b][/color]=[COLOR=#ff00ff]"Folders Demo"[/color]
[COLOR=#008080]    [/color][COLOR=#2e8b57][b]SCROLL[/b][/color]=[COLOR=#ff00ff]"auto"[/color]
[COLOR=#008080]    [/color][COLOR=#2e8b57][b]SINGLEINSTANCE[/b][/color]=[COLOR=#ff00ff]"yes"[/color][COLOR=#008080]>[/color]
  [COLOR=#008080]</head>[/color]

[COLOR=#008080]<script language="VBScript">[/color]
  [COLOR=#804040][b]dim[/b][/color] objShell
  [COLOR=#804040][b]set[/b][/color] objShell [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"WScript.Shell"[/color][COLOR=#804040][b])[/b][/color]

  [COLOR=#804040][b]dim[/b][/color] username
  username [COLOR=#804040][b]=[/b][/color] objShell[COLOR=#804040][b].[/b][/color]Environment[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Process"[/color][COLOR=#804040][b])([/b][/color][COLOR=#ff00ff]"USERNAME"[/color][COLOR=#804040][b])[/b][/color]
  
  [COLOR=#804040][b]dim[/b][/color] basefolderpath
  basefolderpath [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]"C:\Users\"[/color] [COLOR=#804040][b]&[/b][/color] username [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"\Desktop\TESTT1"[/color]

  [COLOR=#804040][b]sub[/b][/color] Window_OnLoad
    self[COLOR=#804040][b].[/b][/color]resizeTo [COLOR=#ff00ff]600[/color][COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]400[/color]
    document[COLOR=#804040][b].[/b][/color]getElementById[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"myFolder"[/color][COLOR=#804040][b]).[/b][/color]innerHTML [COLOR=#804040][b]=[/b][/color] basefolderpath
  [COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]

  [COLOR=#804040][b]sub[/b][/color] createFolders
    [COLOR=#804040][b]On[/b][/color] [COLOR=#804040][b]Error[/b][/color] [COLOR=#804040][b]Resume[/b][/color] [COLOR=#804040][b]Next[/b][/color]

    [COLOR=#804040][b]dim[/b][/color] fso
    [COLOR=#804040][b]set[/b][/color] fso [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Scripting.FileSystemObject"[/color][COLOR=#804040][b])[/b][/color]

    folderpath [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]""[/color]
    [COLOR=#804040][b]if[/b][/color] PickCustommer[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]value[/color] [COLOR=#804040][b]<>[/b][/color] [COLOR=#ff00ff]""[/color]  [COLOR=#804040][b]and _[/b][/color]
       PickFenderType[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]value[/color] [COLOR=#804040][b]<>[/b][/color] [COLOR=#ff00ff]""[/color] [COLOR=#804040][b]and _[/b][/color]
       PickOrderNumber[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]value[/color] [COLOR=#804040][b]<>[/b][/color] [COLOR=#ff00ff]""[/color] [COLOR=#804040][b]then[/b][/color]
      [COLOR=#0000ff] ' create base folder[/color]
       folderpath [COLOR=#804040][b]=[/b][/color] basefolderpath
       [COLOR=#008080]MsgBox[/color] [COLOR=#ff00ff]"Creating folder: "[/color] [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]VbCrLf[/color] [COLOR=#804040][b]&[/b][/color] folderpath
       fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]CreateFolder[/color][COLOR=#804040][b]([/b][/color]folderpath[COLOR=#804040][b])[/b][/color]
       
      [COLOR=#0000ff] ' create folder1[/color]
       foldername1 [COLOR=#804040][b]=[/b][/color] PickCustommer[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]value[/color]
       folderpath [COLOR=#804040][b]=[/b][/color] folderpath [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"\"[/color] [COLOR=#804040][b]&[/b][/color] foldername1
       [COLOR=#008080]MsgBox[/color] [COLOR=#ff00ff]"Creating folder: "[/color] [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]VbCrLf[/color] [COLOR=#804040][b]&[/b][/color] folderpath  
       fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]CreateFolder[/color][COLOR=#804040][b]([/b][/color]folderpath[COLOR=#804040][b])[/b][/color]

      [COLOR=#0000ff] ' create folder2[/color]
       foldername2 [COLOR=#804040][b]=[/b][/color] PickFenderType[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]value[/color]
       folderpath [COLOR=#804040][b]=[/b][/color] folderpath [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"\"[/color] [COLOR=#804040][b]&[/b][/color] foldername2
       [COLOR=#008080]MsgBox[/color] [COLOR=#ff00ff]"Creating folder: "[/color] [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]VbCrLf[/color] [COLOR=#804040][b]&[/b][/color] folderpath  
       fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]CreateFolder[/color][COLOR=#804040][b]([/b][/color]folderpath[COLOR=#804040][b])[/b][/color]
        
      [COLOR=#0000ff] ' create folder3[/color]
       foldername3 [COLOR=#804040][b]=[/b][/color] PickOrderNumber[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]value[/color]
       folderpath [COLOR=#804040][b]=[/b][/color] folderpath [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]"\"[/color] [COLOR=#804040][b]&[/b][/color] foldername3
       [COLOR=#008080]MsgBox[/color] [COLOR=#ff00ff]"Creating folder: "[/color] [COLOR=#804040][b]&[/b][/color] [COLOR=#ff00ff]VbCrLf[/color] [COLOR=#804040][b]&[/b][/color] folderpath  
       fso[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]CreateFolder[/color][COLOR=#804040][b]([/b][/color]folderpath[COLOR=#804040][b])[/b][/color]

       [COLOR=#008080]MsgBox[/color] [COLOR=#ff00ff]"Done."[/color]  
    [COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]if[/b][/color]
  [COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]
[COLOR=#008080]</script>[/color]

[COLOR=#008080]<[/color][COLOR=#008080]body[/color][COLOR=#008080]>[/color]
  [COLOR=#008080]<[/color][COLOR=#008080]h1[/color][COLOR=#008080]>[/color]Creating Folders in:[COLOR=#008080]</h1>[/color]
  [COLOR=#008080]<[/color][COLOR=#008080]h2[/color][COLOR=#008080]><[/color][COLOR=#008080]span[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]id[/b][/color]=[COLOR=#ff00ff]"myFolder"[/color][COLOR=#008080]>[/color][COLOR=#008080]</span></h2>[/color]
  [COLOR=#008080]<[/color][COLOR=#008080]br[/color][COLOR=#008080]>[/color]
  [COLOR=#008080]<[/color][COLOR=#008080]p[/color][COLOR=#008080]>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]label[/color][COLOR=#008080]>[/color]Custommer:[COLOR=#008080]</label>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]select[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]size[/b][/color]=[COLOR=#ff00ff]"1"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]name[/b][/color]=[COLOR=#ff00ff]"PickCustommer"[/color][COLOR=#008080]>[/color]
      [COLOR=#008080]<[/color][COLOR=#008080]option[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]value[/b][/color]=[COLOR=#ff00ff]""[/color][COLOR=#008080]>[/color]Select Custommer[COLOR=#008080]</option>[/color]
      [COLOR=#008080]<[/color][COLOR=#008080]option[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]value[/b][/color]=[COLOR=#ff00ff]"Custommer01"[/color][COLOR=#008080]>[/color]Custommer #1[COLOR=#008080]</option>[/color]
      [COLOR=#008080]<[/color][COLOR=#008080]option[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]value[/b][/color]=[COLOR=#ff00ff]"Custommer02"[/color][COLOR=#008080]>[/color]Custommer #2[COLOR=#008080]</option>[/color]
      [COLOR=#008080]<[/color][COLOR=#008080]option[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]value[/b][/color]=[COLOR=#ff00ff]"Custommer03"[/color][COLOR=#008080]>[/color]Custommer #3[COLOR=#008080]</option>[/color]
      [COLOR=#008080]<[/color][COLOR=#008080]option[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]value[/b][/color]=[COLOR=#ff00ff]"Custommer04"[/color][COLOR=#008080]>[/color]Custommer #4[COLOR=#008080]</option>[/color]
    [COLOR=#008080]</select>[/color]
  [COLOR=#008080]</p>[/color]

  [COLOR=#008080]<[/color][COLOR=#008080]p[/color][COLOR=#008080]>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]label[/color][COLOR=#008080]>[/color]Fender Type:[COLOR=#008080]</label>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]input[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]type[/b][/color]=[COLOR=#ff00ff]"text"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]name[/b][/color]=[COLOR=#ff00ff]"PickFenderType"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]size[/b][/color]=[COLOR=#ff00ff]"20"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]maxlength[/b][/color][COLOR=#008080] [/color]=[COLOR=#008080] [/color][COLOR=#ff00ff]"20"[/color][COLOR=#008080]>[/color]
  [COLOR=#008080]</p>[/color]

  [COLOR=#008080]<[/color][COLOR=#008080]p[/color][COLOR=#008080]>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]label[/color][COLOR=#008080]>[/color]Order Number:[COLOR=#008080]</label>[/color]
    [COLOR=#008080]<[/color][COLOR=#008080]input[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]type[/b][/color]=[COLOR=#ff00ff]"text"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]name[/b][/color]=[COLOR=#ff00ff]"PickOrderNumber"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]size[/b][/color]=[COLOR=#ff00ff]"20"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]maxlength[/b][/color][COLOR=#008080] [/color]=[COLOR=#008080] [/color][COLOR=#ff00ff]"20"[/color][COLOR=#008080]>[/color]
  [COLOR=#008080]</p>[/color]

  [COLOR=#008080]<[/color][COLOR=#008080]input[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]type[/b][/color]=[COLOR=#ff00ff]"button"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]value[/b][/color]=[COLOR=#ff00ff]"Create"[/color][COLOR=#008080] [/color][COLOR=#2e8b57][b]onClick[/b][/color]=[COLOR=#ff00ff]"createFolders"[/color][COLOR=#008080]>[/color]
[COLOR=#008080]</body>[/color]
[COLOR=#008080]</html>[/color]
 
Hi Mikrom,

I have it working now with the script.

What is the script to open the last created file?


2022-04-07_10_44_09-Window_xhcfoq.png
 
Hi TvdH1981
> What is the script to open the last created file?

Try to add at the end of the script following
WshShell.Run folderpath
 
I added the above statement at the end of the script I posted here on 30 Mar 22 07:46
I tried it and on my computer it works fine, it opens the last folder automatically.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top