Relative file path in Batch

mosleyrs

New Member
I'm trying to write a batch file to run a command line on all of the files in a directory structure and copy the resulting outputs to the same structure but at an alternate root

ie
batch file located at c:\one\two
file to process located at c:\one\two\three\four\five.extension
I want to move the output file five.extension2 now located at c:\one\two\three\four
to new location %NEW_PATH%\three\four

~dp0 will give me the batch path (c:\one\two)
~f will give me the full file path for five.extension (c:\one\two\three\four\five.extension)
~n gives the file name I care about (five)
but I can't seem to find a way to parse out the "\three\four" for the move command (%NEW_PATH%\three\four)

any help would be appreciated
 

My Computer

I'm trying to write a batch file to run a command line on all of the files in a directory structure and copy the resulting outputs to the same structure but at an alternate root

ie
batch file located at c:\one\two
file to process located at c:\one\two\three\four\five.extension
I want to move the output file five.extension2 now located at c:\one\two\three\four
to new location %NEW_PATH%\three\four

~dp0 will give me the batch path (c:\one\two)
~f will give me the full file path for five.extension (c:\one\two\three\four\five.extension)
~n gives the file name I care about (five)
but I can't seem to find a way to parse out the "\three\four" for the move command (%NEW_PATH%\three\four)

any help would be appreciated

I know this sounds rather dumb of me, maybe I'm just misinterpreting the question, but can't you just copy and paste the created batch file to the new location, sounds like a long way to go to move a file from one place to another, again correct me if you think I've misinterpreted the question

MrNeeds
 

My Computer

System One

  • Manufacturer/Model
    Custom Build
    CPU
    Intel Q6600 @ 2.8GHz
    Motherboard
    Evga NF78-CK-132-A 3-Way SLI
    Memory
    8Gb DDR2 Corsair Dominator @ 1066Mhz 5-5-5-15
    Graphics Card(s)
    EVGA 560 GTX SC FTW 1GB
    Sound Card
    Realtek ALC888 7.1 Audio, Logitech G35 7.1 Surround Headset
    Monitor(s) Displays
    Dell S2409W 16:9, HDMi, DVI & VGA
    Screen Resolution
    1920 x 1080
    Hard Drives
    Samsung 7200rpm 250Gb SATA,
    Samsung 7200rpm 750Gb SATA,
    WD 7200rpm 1TB SCSI SATA.
    PSU
    Xigmatek 750W Quad sli quad core 80% eff
    Case
    Antec 900 Gaming Case
    Cooling
    Zalman CNPS9700-NT NVIDIA Tritium, Dominator RAM cooler
    Keyboard
    Logitech generic keyboard
    Mouse
    Razor Lachesis Banshee V2 Blue, 4000DPI
    Internet Speed
    16Mb Sky bb
    Other Info
    Wireless Gaming Receiver for Windows, Wireless Xbox 360 Pad, Wireless Xbox 360 Les Paul Guitar
This will get put in a loop that recursively acts on all of the files in a structure so this will get run on 100s of files. And I was using copy as an example, its actually a video encode command line. IE, I want to convert all of my home movies into smaller files for posting on the web but keep the same sort of directory structure without polluting my home movies directory.
 

My Computer

Hello and welcome to the Vista Forums!

You might be able to do it in a batch file, you certainly could in a Visual Basic Script, but I am not familiar with either, and it all seems a bit pointless.

I can see that you don't want to modify your original movies, but how about copying your entire library to a new copy (duplicate it) and then just allow the script to modify the (now duplicated) originals?

Richard
 

My Computer

System One

  • Manufacturer/Model
    Dell XPS 420
    CPU
    Intel Core 2 Quad Q9300 2.50GHz
    Motherboard
    Stock Dell 0TP406
    Memory
    4 gb (DDR2 800) 400MHz
    Graphics Card(s)
    ATI Radeon HD 3870 (512 MBytes)
    Sound Card
    Onboard
    Monitor(s) Displays
    1 x Dell 2007FP and 1 x (old) Sonic flat screen
    Screen Resolution
    1600 x 1200 and 1280 x 1204
    Hard Drives
    1 x 640Gb (SATA 300)
    Western Digital: WDC WD6400AAKS-75A7B0

    1 x 1Tb (SATA 600)
    Western Digital: Caviar Black, SATA 6GB/S, 64Mb cache, 8ms
    Western Digital: WDC WD1002FAEX-00Z3A0 ATA Device
    PSU
    Stock PSU - 375W
    Case
    Dell XPS 420
    Cooling
    Stock Fan
    Keyboard
    Dell Bluetooth
    Mouse
    Advent Optical ADE-WG01 (colour change light up)
    Internet Speed
    120 kb/s
    Other Info
    ASUS USB 3.0 5Gbps/SATA 6Gbps - PCI-Express Combo Controller Card (U3S6)
I'm trying to write a batch file to run a command line on all of the files in a directory structure and copy the resulting outputs to the same structure but at an alternate root

ie
batch file located at c:\one\two
file to process located at c:\one\two\three\four\five.extension
I want to move the output file five.extension2 now located at c:\one\two\three\four
to new location %NEW_PATH%\three\four

~dp0 will give me the batch path (c:\one\two)
~f will give me the full file path for five.extension (c:\one\two\three\four\five.extension)
~n gives the file name I care about (five)
but I can't seem to find a way to parse out the "\three\four" for the move command (%NEW_PATH%\three\four)

any help would be appreciated

What I did was create a small function that got the length of the top level directory (ie C:\one\two) and used this to get the substring I needed out of %%~dpi (I assume you are going through it in a batch file loop like me where %%i is the current file). Then something like

set folder=%%~dpi
set folder=!folder:~%len%!

would get the relative file path you are after.

The string length function and rest of the code with comments on batch file string manipulation are here. (it's part of a larger script that compares file last-modified field before copying)
 

My Computer

Back
Top