Windows 10: How to get my own path in a batch-file.

Discus and support How to get my own path in a batch-file. in Windows 10 Network and Sharing to solve the problem; Default answer is %~dp0. And most times this will work fine. But there is a bug in cmd.exe which will prevent this from working correctly under certain... Discussion in 'Windows 10 Network and Sharing' started by microtiger, Jul 23, 2021.

  1. How to get my own path in a batch-file.


    Default answer is %~dp0. And most times this will work fine. But there is a bug in cmd.exe which will prevent this from working correctly under certain circumstances if you use double quotes to call the batch. Double quotes are necessary if the name or path of the batch file contains spaces. So for convenience everybody adds double quotes on all filenames. I struggled very long with this bug. This example will show the bug: Create this batch file, name it "z z.cmd" and put it in a folder specified by %path% or f.ex. in C:\Windows. @Echo off echo.%~x0. echo.%~dpnx0. goto :eo

    :)
     
    microtiger, Jul 23, 2021
    #1
  2. fahnix Win User

    Batch files fail pathing and [%04d]

    1 When running in Administrator mode batch files automatically take on the Windows\System32 folder unless a prefix is added to the top of the file.

    command example: copy file1.txt "C:\Users\Public\Test\."

    result copies file in current folder to "C:\Users\Public\Test\file1.txt"

    result from batch file as admin is an error stating "File not found" because Admin mode attempts to call commands listed in file from [Windows\System32] folder.

    include [cd %~dp0] at top of batch file to ensure commands run from the folder the batch file resides in.

    2 When running ffmpeg.exe in one folder and writing files to another folder from a batch file Windows automatically pastes the entire path and the batch file name prior to every attempted file write.

    ffmpeg command example :

    bin\ffmpeg.exe -i "C:\Users\JoeMatize\Videos\Logitech Webcam\video 3.wmv" -r 15 "frames-%04d.bmp"

    then windows creates 15 frames per second naming files [frames-0001.bmp] through [frames-0015.bmp] for the 1st second and continuing through the entire file

    But ffmCmd.bat file contains the command attempts to create the output file as...

    "C:\_dev\_Video\FFMPeg_Zeranoe\ffmpeg-20160517-git-af3e944-win64-static\ffmCmd.bat4d.bmp"

    ffmpeg fails when it is unable to acquire a new name for the sequential files.

    is there another command that will fix the batch call to ffmpeg, like the one that fixes the administrative mode path?

    When will Microsoft fix the batch files so they work consistently across the board?
     
    fahnix, Jul 23, 2021
    #2
  3. oily_17 Win User
    Batch Files Knowledge Base

    Don't use batch files very much but one I find useful is for creating a list of files in a directory.
    Just copy the text below into Notepad and save as Filelist.bat

    dir /a /-p /o:gen >filelist.txt

    When you run it from a folder it will create a Filelist.txt file,in the same folder, that lists all the files in that folder.Useful when you are too lazy to type all the files out yourself.
     
    oily_17, Jul 23, 2021
    #3
  4. How to get my own path in a batch-file.

    Batch Files Knowledge Base

    Very nice and usefull thanks for contributing.
     
    AphexDreamer, Jul 23, 2021
    #4
Thema:

How to get my own path in a batch-file.

Loading...
  1. How to get my own path in a batch-file. - Similar Threads - own path batch

  2. Batch Files

    in Windows 10 Gaming
    Batch Files: How do i make it that my batch file puts itself in to startup https://answers.microsoft.com/en-us/windows/forum/all/batch-files/6156404d-20d4-4f58-bee5-14629dbf7b10
  3. Batch Files

    in Windows 10 Software and Apps
    Batch Files: How do i make it that my batch file puts itself in to startup https://answers.microsoft.com/en-us/windows/forum/all/batch-files/6156404d-20d4-4f58-bee5-14629dbf7b10
  4. Create batch files with Batch?

    in Windows 10 Software and Apps
    Create batch files with Batch?: How to create Batch and VBS files with Batch? So I write a batch file which I then convert to exe that creates new folders in a certain directory and then creates batch and VBS files with a certain content and saves them in the created folder. So it's similar to a program...
  5. How to get full filename and path of files

    in Windows 10 Network and Sharing
    How to get full filename and path of files: I am using Windows 10. I have a directory with many subfolders. I want to get a list of all the files full path in all the subdirectories. For example, C:\Parent Directory\Sub Directory\My File.txt I want to put all these file names and their directories into a text...
  6. Batch File

    in Windows 10 Support
    Batch File: I need a batch file to create a folder with sub folders. The sub folders will be named the current date, they will go in a folder on c drive. For example we can call the folder test and it would be in documents on c drive. Every time we run the batch file it would create a...
  7. Trouble with batch files and paths

    in Windows 10 Support
    Trouble with batch files and paths: Running win 10 v 1909 build 18363.720. I am pretty green with batch files and paths. I am trying to automate and editing process with mkvpropedit on a bunch of MKV files. I put the bat file in the same folder as the mkvs. Batch file contains: @echo off for %%a in (*.mkv)...
  8. Batch file does not recognize spaces, unable to get it to follow UNC path with spaces.

    in Windows 10 Customization
    Batch file does not recognize spaces, unable to get it to follow UNC path with spaces.: Hello, I am trying to create a batch file which will pull an .exe from a UNC file path that has spaces in it but I can't figure out how to use the quotations to make it work. So far I've tried the following: @echo off start "\\servername\sharepath\share...
  9. How to Batch Rename files ?

    in Windows 10 Software and Apps
    How to Batch Rename files ?: I have a lot of files i want to give names to. I already found a way to get names into a text I need. So all these names i have in text, i want to give to other files. How do i do this in a batch process ? Currently trying to learn FastStone Image viewer. Seems to be...
  10. How to get/display full path *and* file name of a file?

    in Windows 10 Support
    How to get/display full path *and* file name of a file?: Hi All, Any way to get/display the full path and file name of a file? It's easy to get the full path, but I want to get the path and file name. I know I can grab them separately. Can I get them together? How? I did a google and youtube search and didn't find any hits....