Batch File: Storing Folder Name in Variable

Discussion in 'Software' started by SimpleMan46, Jun 11, 2004.

  1. SimpleMan46

    SimpleMan46 Private E-2

    What I'm trying to do is take a path string such as:
    c:\files\folder1
    and somehow get "folder1" stored into a variable.

    Is this possible?

    I'm trying to make a batch file that will rename files in a folder to have the same name as the folder. This little bit is the only thing that is stumping me. Any help is appreciated, thanks!
     
  2. †T-Rex †

    †T-Rex † Specialist

    I know that there are environment variables, like %Path% or %SystemRoot%. The variable %SystemRoot% goes straight to C:\WINDOWS\System32 if I'm not mistaken. I know this doesn't help much, but I'm hinting around the answer simply because I can't remember for sure how to do what you're asking for.
     
  3. goldfish

    goldfish Lt. Sushi.DC

    if you were changing to the folder1 directory, you could do somthing like

    SET %foldername%=folder1
    cd %foldername%

    you can use %cd% to get the current directory.

    It sounds like what you are doing is to trim the full path to get the name of the current folder.. and ive no idea how to do that in command line batch
     
  4. SimpleMan46

    SimpleMan46 Private E-2

    I'm starting to think this might not be possible as well. To elaborate on what I'm trying to do, I'm making a "droplet" that when you drag a folder onto it, it renames the folder's contents to have the same name as the folder. I've figured out how to do the renaming, I just can't figure out how to get the folder's name.
     
  5. SimpleMan46

    SimpleMan46 Private E-2

    After doing a little more searching, it looks like I could trim the path string pretty easily using VBScript, which I have limited experience with. I still need this to be run from a bat file though. So, now this is what I'm trying to figure out:
    -I need to pass the path string from the batch file to the VBScript.
    -The VBS needs to trim the string (I can figure this part out)
    -The string needs to be passed back to the batch file.

    Anybody have experience with passing variables between BAT and VBS scripts? Thanks for the help.
     
  6. Kodo

    Kodo SNATCHSQUATCH

    why on earth do you need a batch file. What ever you can do with a batch file, you can do with VBS and more.
     
  7. SimpleMan46

    SimpleMan46 Private E-2

    Just because of some other actions that need to be performed with the script. They could probably be done with VBS, but I just don't know how. Anyway, I figured out what I was trying to do, thanks for the help!
     
  8. Kodo

    Kodo SNATCHSQUATCH

    Kind of odd that you had to figure out how to do it with a batch file and you didn't "know" (want to figure out) how to do it with VBS..;) only pointing out the obvious.. that's why we're here bro, To Help :)
     
  9. goldfish

    goldfish Lt. Sushi.DC

    I was thinking the same thing actually, to use a .vbs or a windows script... would be a whole lot easier.
     
  10. dingoboy

    dingoboy Private E-2

    Kodo, you say anything that can be done with batch can be done with vbscript. I have searched high and low, far and wide....ok just on the net, to solve a scripting problem I am having. Any idea how I could set up a share remotely? I have been trying to use the following script but it only allows sharing on a local drive, also when I try to use it with the variable UserN I get a bad name error.

    UserN="jbloggs"
    homefolder="<A href="file://\lmsasstudents\"&Usern">\\lmsas\students\"&Usern
    set objFold = CreateObject( "Scripting.FileSystemObject" )
    objFold.CreateFolder homefolder
    Const FILE_SHARE = 0
    Const MAXIMUM_CONNECTIONS = 25
    strComputer="."
    Set objWMIService=GetObject("winmgmts:"&"{impersonationLevel=impersonate}!\\"&strComputer&"\root\cimv2")
    Set objNewShare=objWMIService.Get("Win32_Share")
    errReturn=objNewShare.Create(homefolder,UserN,FILE_SHARE,MAXIMUM_CONNECTIONS,"Home drive.")
    WScript.Echo homefolder
    Wscript.Echo errReturn

    Any suggestions would be greatly appreciated.
     
  11. Kodo

    Kodo SNATCHSQUATCH

  12. dingoboy

    dingoboy Private E-2

    I actually crossed this page in my travels yesterday. The problem I am having is not mapping to a remote share but creating the share. Part of my user creation requires that I make a network home folder for them on the server then setting it up as a shared folder so they can access it.
     
  13. Kodo

    Kodo SNATCHSQUATCH


MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds