Jump to content

quijibo

Member
  • Posts

    5
  • Joined

  • Last visited

  • Donations

    0.00 USD 
  • Country

    Canada

Everything posted by quijibo

  1. Taskkill was implemented in Windows XP. If you're running an older OS, download pskill in it's place. If you drop pskill into your %WINDIR% the code of line three would be: pskill firefox If you put pskill in the same directory as the batch file the syntax of line three would be: .\pskill firefox I've found pskill to be more powerful than taskkill at killing some apps.
  2. In case anyone looks this thread up in the future, I came up with another way of doing this. It took me some long, hard thought to come up with something that is ultimately so simple. It helps to know all of your built-in variables. @ECHO OFF CD /D "%~dp1" FOR %%G IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF '"%CD%"'=='"%%G:\"' SET LD=%%G IF NOT '"%LD%"'=='""' GOTO :NEXT CALL :LASTDIR "%CD%" :LASTDIR SET LD=%~nx1 :NEXT ECHO %LD% PAUSE The first line assumes that you're relying on a %1 variable (which represents either a file or a directory) that has been passed from a previous routine. The quotes from line four are not part of the LD variable when it is created in the :LASTDIR section. The %~nx1 ensures that any directories named like folder_name.stuff.more.stuff are not truncated after the word name. This works for any directory, even ones that end up just root drive letters like C: (that is what line two does). If you make this into a .bat file, you can test it by running the batch file in any directory, even when you have no predefined %1 variable. When there is no %1, the LD variable will always return the last directory in the path that the batch file is running from. I honestly still can't wrap my head around the syntax of most of the solutions posted above since I'm no command line guru, so I came up with this one because I understand it 100%. Thanks to Delprat for making me think about this again.
  3. Yeah it seems like something a lot of people would need to do in their scripts, but I just couldn't find any specialized exe or routine for doing it.
  4. Thanks! I think I have everything I need with the three posts here. Preferably I would like to do this without using a FOR/CALL routine. I was on the verge of doing the solution in the first post where text would pipe into a file, then be parsed for the last section after the / but that parsing process is way beyond my abilities, for now. I think Yzöwl has it, but the other solutions I can integrate into what I'm trying to do as well, just not for my original problem.
  5. My question pertains to a simple batch file that will run on Windows 2000 and later. Basically, I want to know if there is some way of finding the last directory name in a path and assigning only that last directory name as a variable. Here's what I'm talking about: Say my path is "c:\test path\folder1\Last Directory" and this path is found in the batch file while doing a "For /R (c:\test path) %%d IN (*.pdf) ...etc etc." Say a PDF is located in "c:\test path\folder1\Last Directory" and that particular PDF can now be represented as %1. Say I have a compression operation that will compress the PDF file, but it needs the name of the directory (in this case "Last Directory") the PDF file is in as a name for the final compressed file. So the file would end up being called "Last Directory.zip." How can I create a variable that gets only the last directory in a path? Stuff like %~dp1 or %~p1 doesn't work because it grabs the whole path, not just the last directory name. And %~n1 doesn't work because then it using the filename of the PDF and not the directory name. What I would like to do is: SET LASTDIRNAME=%VAR (where %VAR is the solution to my problem above) and then I could do this when naming my zip files during the batch: zip "%~dp1%1" "%LASTDIRNAME%.zip" ; With the variables removed it would look like this: ; zip "c:\test path\folder1\Last Directory\somefile.pdf" "Last Directory.zip"
×
×
  • Create New...