BAT File Command Help (3 Viewers)

EzGoingKev

Registered User.
Local time
Yesterday, 19:08
Joined
Nov 8, 2019
Messages
191
Good afternoon.

I have BAT file that creates a text file with directory of the folder that it is in and puts in on the desktop. Here is the code:

dir "%~dp0" /b > "%USERPROFILE%\Desktop\list.txt"

This works 100% for me but I would like to append the name of the folder the BAT file is in to the file name.

For example if the BAT file was in a folder called Dog the BAT file would create a file called "Dog_list.txt".

Is there a simple way to get the folder name added to the filename?
 
Doubtless a BAT person here will help you out, but if you want to switch to something infinitely easier to read, document, make conditional, and maintain, I'll be happy to provide a VBScript (.vbs) file that will do what you're wanting. Will take a moment to do so if you decide you wish.
 
Thanks for the reply.

I do not know what a VBScript file is.

A couple of things first.

Anyone can just click on the BAT file and it will create a file on their desktop name list.txt that has the folder's directory in it. I am looking for something that all the user has to do is click on it.

This is on a corporate server. IT has the permissions locked down pretty tight. For example, I cannot open a PowerShell window for those folders. Will this prevent the VBS from running?
 
90% chance the vbs would still run, i've had mostly corporate experience including powershell restrictions but generally they dont' prevent vbs from running on your local machine. and yes, double clicking on would instantly run it. i'll whip it up just for fun and if you dont use it that's OK.
have to go to traffic court wiht my daughter (she has a lead foot apparently), but will be back later this afternoon.
 
Good afternoon.

I have BAT file that creates a text file with directory of the folder that it is in and puts in on the desktop. Here is the code:

dir "%~dp0" /b > "%USERPROFILE%\Desktop\list.txt"

This works 100% for me but I would like to append the name of the folder the BAT file is in to the file name.

For example if the BAT file was in a folder called Dog the BAT file would create a file called "Dog_list.txt".

Is there a simple way to get the folder name added to the filename?

See if this helps at all
 
I haven't used batch files in a while, but here's what I came up with.
Code:
for %%i in (%cd%) do set fldr=%%~nxi
dir "%~dp0" /b > "%userprofile%\desktop\%fldr%_list.txt"
Hope that helps...
 
Download the attachment, change the extension from .txt to .vbs
Click to run
Yes...it's more code, but easy to read and "add stuff" to / enhance/change.
 

Attachments

Users who are viewing this thread

  • Back
    Top Bottom