Jump to content

Can You Help Me Modify This Script?


Recommended Posts

I have a script for a batch file which I use quite often.

This batch file will "move" (not delete) files I select from a folder to a backup folder on C:\

Maybe someone can help me modify it a little.

I would like to be able to move a bunch of files at one time from a folder, while leaving the few files I want to keep in the folder.

For example, with the inf folder (C:\WINDOWS\inf). I would like to be able to move all the inf files I don't want, and just keep the few I do want, without having to write in every inf file I don't want.

(Did I explain that right?)

I guess I'm asking, can this script be modified to keep a few files in a folder, and move all the others?

See, I want to move 600 files, and keep about 30 files, but I'd rather type in the names of 30 files, than 600 files.

-------------------------------------------------

IF NOT EXIST "c:\backup\WINDOWS\system32" md c:\backup\WINDOWS\system32 
MOVE c:\WINDOWS\system32\6to4svc.dll c:\backup\WINDOWS\system32\
MOVE c:\WINDOWS\system32\aaaamon.dll c:\backup\WINDOWS\system32\
MOVE c:\WINDOWS\system32\acledit.dll c:\backup\WINDOWS\system32\
MOVE c:\WINDOWS\system32\admparse.dll c:\backup\WINDOWS\system32\

-------------------------------------------------

Edited by un4given1: Please remember to use CODE tags.

Link to comment
Share on other sites


Maybe this will help. If I make the batch file to move all files (*.*) is there a way to protect and leave alone individual files?

Like say I wanted to protect and leave alone "layout.inf".

Could I insert layout.inf in some way to protect it and leave it in the folder?

IF NOT EXIST "c:\backup\WINDOWS\inf" md c:\backup\WINDOWS\inf

MOVE c:\WINDOWS\system32\*.* c:\backup\WINDOWS\system32\

(un4given1, sorry if this doesn't show up in code tag. I just don't know how to do that yet.)

Link to comment
Share on other sites

You can move your 30 files to a temp folder, do what you what in the folder you're working on and then move back your 30 files to the original folder.

But you'll have to type the 30 files name.

:)

Link to comment
Share on other sites

Thanks, jdoe. That's what I've been doing.

You know, I have this Temp File Cleaner named, HDValet. You can configure it with the *.* command and point it toward a folder, but at the same time, you can protect certain files with it.

That tells me there has to be a way of doing it. I'll keep looking. Thanks, all, for your help.

Link to comment
Share on other sites

Try This Then For Cmd

copy C:\backup\WINDOWS\*.inf c:\backup\WINDOWS\system32\

Move C:\backup\WINDOWS\*.inf c:\backup\WINDOWS\system32\

VBS Script

Move

Set Shell = CreateObject("Shell.Application")

set Folder = Shell.NameSpace( "c:\backup\WINDOWS\system32\")

  if not Folder is nothing Then

  Folder.MoveHere( "C:\backup\WINDOWS\*.inf")

  end If

VBS Script

Copy

Set Shell = CreateObject("Shell.Application")

set Folder = Shell.NameSpace( "c:\backup\WINDOWS\system32\")

  if not Folder is nothing Then

  Folder.CopyHere( "C:\backup\WINDOWS\*.inf")

  end If

Blue Change To Match Your Computer Location

Green Is Just Asking To Keep The Test Folder

Orange Is The Script Checking To See If The Folder Is There

Grey Is The Copy Part Of The Script

Red Is The Location Or Files As A Varible

This Color Is The Folder Or File To Remove.

Purple Is For Script Notes

Notes

If You Want To Use One Varible For The EndSpot To Delete

The Folder Then it Must Look Like This

How It Is In The Script

Dim EndSpot : EndSpot =("D:\TestCopy1FileType\")

Re Edit

Dim EndSpot : EndSpot =("D:\TestCopy1FileType")

In The Script The Line Will Look Like this

EndSpot & "\"

Also For Every If There Must Be A End If

Test The VBS Script

Dim Shell : Set Shell = CreateObject("Shell.Application")

Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")

Dim EndSpot : EndSpot =("D:\TestCopy1FileType\")

Dim CopyFiletype2 : CopyFiletype2 =("C:\MyScripts\Scripts-Msfn-Uploads\*.exe")

If Not FSO.FolderExists(EndSpot) Then

Fso.CreateFolder(EndSpot)

Else

If FSO.FolderExists(EndSpot) Then

End If

End if

  set Folder = Shell.NameSpace(EndSpot) ' directory to copy to

  if not Folder is nothing Then

  Folder.CopyHere(CopyFiletype2) 'files or folder

  Z1 = MsgBox ("Would You Like To Keep The Test Folder" & vbCrLf & "Yes To keep" & Space(9) & "No To Delete", 4 + 64, "Copy And Delete template")

  If Z1 = Vbno Then

    F =FSO.deleteFolder("D:\TestCopy1FileType")

  Else

  If Z1 = VBYes Then

  MsgBox "Keeping The Test Folder", 0 + 32, "Keep The Test"

  end If

  end If

      end If

Link to comment
Share on other sites

Thanks, gunsmokingman. You put a lot of effort into that for me, and I appreciate it.

Just now, a friend of mine at Jan's "Graphics an Stuff" had a splendid solution.

Per Xrs2: "I would recommend just making the script move the files you want back (after it moves them all the first time)."

So, I wrote this...and it works! (One happy camper here.)

IF NOT EXIST "c:\backup\WINDOWS\inf" md c:\backup\WINDOWS\inf
MOVE c:\WINDOWS\inf\*.* c:\backup\WINDOWS\inf\
IF NOT EXIST "c:\WINDOWS\inf" md c:\WINDOWS\inf
MOVE c:\backup\WINDOWS\inf\msports.inf c:\WINDOWS\inf\

Figured out this Code thing, un4given1. I first have to disable PopUpCop. (I can be really dumb a lot of the time.)

Link to comment
Share on other sites

  • 2 weeks later...

BOld, try this VBS.

set fso = createobject("scripting.filesystemobject")
set folder = fso.getfolder("c:\WINDOWS\system32")
For Each file in folder.files
Filename = file.name
If fso.GetExtensionName(file.path)="ini" Then
 If Filename <> "fileiwanttokeep1.ini" And _
 Filename <> "fileiwanttokeep2.ini" And _
 Filename <> "fileiwanttokeep3.ini" And _
 Filename <> "fileiwanttokeep4.ini" And _
 Filename <> "fileiwanttokeep5.ini" And _
 '----add as many as you want...----
 Filename <> "fileiwanttokeep6.ini" Then
 Set f = fso.GetFile(file.path)
 f.move c:\backup\WINDOWS\inf
 End If
End If
Next
MsgBox "ok"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...