Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

DOS .bat file


  • Please log in to reply
7 replies to this topic

#1 MarkBeepBeep

MarkBeepBeep

  •  Avatar image
  • Members
  • 187 posts
  • OFFLINE
  •  
  • Local time:01:09 AM

Posted 09 November 2022 - 12:47 PM

I didn't know the best forum to post this too.

Hopefully this one is appropriate.

 

I am working in Win10, however I believe a standard .bat file can accomplish what

I'm after.

 

Here's what I'd like to do.

 

I would like to create a loop that circles through each file in a given folder,

takes the name of each file and searches for this name in a list of folders (names).

If the folder name is found, then move the file with the same name, into this

folder.

 

I'm sure this would be fairly easy to set up. My DOS .bat skills aren't up to this

task though.

 

Can anyone here help me?

 

More clarification with an example:

 

Filename:

'Leaf in garden.jpg'

 

Folder:

'Garden'

 

Move 'Leaf in garden.jpg' into folder 'Garden'.


Edited by MarkBeepBeep, 09 November 2022 - 02:27 PM.


BC AdBot (Login to Remove)

 


#2 SamHobbs

SamHobbs

  •  Avatar image
  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:09 PM

Posted 09 November 2022 - 05:17 PM

Are you using Windows? DOS is not supported in current versions of Windows.

#3 MarkBeepBeep

MarkBeepBeep
  • Topic Starter

  •  Avatar image
  • Members
  • 187 posts
  • OFFLINE
  •  
  • Local time:01:09 AM

Posted 09 November 2022 - 06:09 PM

Are you using Windows? DOS is not supported in current versions of Windows.

Thanks Sam.

I am using Win 10 and I am sure .bat files work in this version.

 

I found an article today about .bat files and there is one example

that is very close to what I am looking for.

 

Here is the link.

Scroll down to 'File Organizer'.



#4 SamHobbs

SamHobbs

  •  Avatar image
  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:09 PM

Posted 10 November 2022 - 12:02 AM

Sure, batch files work in a Windows Command Prompt window but as I said you cannot use DOS in current versions of Windows. People are in the habit of saying DOS but mistakes like that can cause confusion.

 

There are many alternatives to batch files that are very much more flexible and powerful. You should choose one and learn it. The alternative being used by Microsoft is PowerShell. I don't like PowerShell because I am a C# programmer and I think they should be using a scripting version of C# (or at least VB) instead of inventing a totally different language unique to that environment.

 

Other possibilities are VBScript, JavaScript and Pythion. They are all reasonable alternatives to batch files. JavaScript  can be used in Windows outside of a browser. I would use C# instead of batch files for all but very simple things.


Edited by SamHobbs, 10 November 2022 - 12:04 AM.


#5 MarkBeepBeep

MarkBeepBeep
  • Topic Starter

  •  Avatar image
  • Members
  • 187 posts
  • OFFLINE
  •  
  • Local time:01:09 AM

Posted 10 November 2022 - 11:12 AM

Sure, batch files work in a Windows Command Prompt window but as I said you cannot use DOS in current versions of Windows. People are in the habit of saying DOS but mistakes like that can cause confusion.

 

There are many alternatives to batch files that are very much more flexible and powerful. You should choose one and learn it. The alternative being used by Microsoft is PowerShell. I don't like PowerShell because I am a C# programmer and I think they should be using a scripting version of C# (or at least VB) instead of inventing a totally different language unique to that environment.

 

Other possibilities are VBScript, JavaScript and Pythion. They are all reasonable alternatives to batch files. JavaScript  can be used in Windows outside of a browser. I would use C# instead of batch files for all but very simple things.

Thanks Sam for this info.

I guess I am using old terminology then.

 

To me it really doesn't matter what computer script/language is used to do the job.

I just thought of a DOS .bat file because I was familiar with its use for decades.

 

I could easily open a Command prompt to run the code if it works.

If there is an easy C# script I could use and it doesn't require anything intensive for setup,

I'd be game for that.

I like the .bat files because they are native to MS and don't require any additional installations.



#6 SamHobbs

SamHobbs

  •  Avatar image
  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:09 PM

Posted 10 November 2022 - 10:43 PM

PowerShell, JavaScript and VBScript are all included with Windows.
 
I am a little busy at the moment, maybe I will get back to this later. For now you can look at Cscript - VBScript - SS64.com. It will at least give you an idea of what I mean. Cscript and Wscript can be used for either VBScript or JavaScript. In the past Scripting Blog - A place to learn about PowerShell and share stories of automation was called The Scripting Guy and a good place to get VBScript and JavaScript scripts but now it is all about PowerShell. If you are willing to learn PowerShell then you will find many others eager to help.



#7 MarkBeepBeep

MarkBeepBeep
  • Topic Starter

  •  Avatar image
  • Members
  • 187 posts
  • OFFLINE
  •  
  • Local time:01:09 AM

Posted 19 August 2023 - 01:53 PM

PowerShell, JavaScript and VBScript are all included with Windows.
 
I am a little busy at the moment, maybe I will get back to this later. For now you can look at Cscript - VBScript - SS64.com. It will at least give you an idea of what I mean. Cscript and Wscript can be used for either VBScript or JavaScript. In the past Scripting Blog - A place to learn about PowerShell and share stories of automation was called The Scripting Guy and a good place to get VBScript and JavaScript scripts but now it is all about PowerShell. If you are willing to learn PowerShell then you will find many others eager to help.

Hi Sam.

 

I was just reviewing some of my older posts and I remembered this one.

I never pursued the programming ideas you mentioned as I was looking for a simple solution to my problem.

 

At the time you said you were a little busy.

Would you have some free time now to come up with a short script that would move the files in the manner I mentioned in my OP?

 

A few more examples:

 

Filename:

'Leaf in garden.jpg'

'Soil in garden.txt'

'Garden bird.jpg'

'Containers in basement.txt'

etc. (same for other files)

 

Folder:

'Garden'

'Basement'

etc.

 

Move:

   'Leaf in garden.jpg'

   'Soil in garden.txt'  

   'Garden bird.jpg

into folder 'Garden'

 

  'Containers in basement.txt'

into folder 'Basement'


Edited by MarkBeepBeep, 19 August 2023 - 01:54 PM.


#8 SamHobbs

SamHobbs

  •  Avatar image
  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:09 PM

Posted 20 August 2023 - 12:28 PM

The following are good introductions to VBScript.

Also see:

The following are samples of enumerating the files in a folder.

The first one above is from the ScriptingGuy. That site has a huge collection of articles and samples but they are not as easy to find as they should be, due to Microsoft's switch to  PowerShell.

 

There are also books about VBScript and related subjects.

Look over all that. If you need help creating a list and searching the list then return here.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users