Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Help with unknown path  (Read 3019 times)

0 Members and 1 Guest are viewing this topic.

JoshCM

    Topic Starter


    Greenhorn

    • Experience: Familiar
    • OS: Windows 10
    Help with unknown path
    « on: June 26, 2018, 11:50:09 AM »
    Hello everyone!
    I need some help here and I'm sure the answer is right in front of my face, I am just missing it.

    I want to use this bat file to "release" a project at my work.
    Which is basically copying a couple files to a job folder.
    Job number is a variable and the only known one.
    Job name is always a string of text with spaces and symbols which could cause a problem.
    But the name is always irrelevant so I want to get past this by using *
    These components are the label of the folder for example (Y:\1121 TEST JOB)
    I can verify this path exists with

    Code: [Select]
    if exist "Y:\%jobNumber%*" (
    goto success
    )
    goto fail

    Now I need to copy a set of files to different sub folders within that job folder.
    This is where the problem comes. I'm actually unzipping these files due to a lack of knowledge on how to properly copy them the way I want to but that doesn't matter, either way you think is best is fine here.

    Code: [Select]
    set pathStart="%~dp0\job.zip"
    set pathEnd="Y:\%jobNumber%*"
    "C:\Program Files\Winrar\WinRAR.exe" x %pathStart% *.* %pathEnd%

    I realize that my use of the * symbol within the quotes is screwing me here but I've tried this a few ways and no matter what it always unzips to the pathStart which is where the bat is located not where the job folder is.

    If you have any suggestion to make this work I would greatly appreciate it!
    Thanks -Josh

    Salmon Trout

    • Guest
    Re: Help with unknown path
    « Reply #1 on: June 26, 2018, 01:40:07 PM »
    Please describe the job in more detail. Please do that. Also, please try to answer the following

    Quote
    Now I need to copy a set of files to different sub folders within that job folder.

    What sub folders? Do they exist already? How is the script to know which files go into which sub folders?

    Please note that while an asterisk wildcard will find a folder that matches the string* spec, it won't magically read your mind and create folders based on what you want.

    Quote
    "C:\Program Files\Winrar\WinRAR.exe" x %pathStart% *.* %pathEnd%

    What do you think the bit in bold red will do?

    From the WinRar help file:

    Quote
    unpack the archive Info.rar to folder d:\data
    WinRAR x Info.rar d:\data\




    JoshCM

      Topic Starter


      Greenhorn

      • Experience: Familiar
      • OS: Windows 10
      Re: Help with unknown path
      « Reply #2 on: June 27, 2018, 06:05:33 AM »
      Here is the full code. (see bottom) I've updated it a bit since I posted this question but I'm still pretty much stuck at the same spot. I've learned a little bit from you already though. Even in another post you were involved in which gave me an idea for this! So thank you!  ;D

      The sub folders are the same in every job folder and I tell the program the path at the beginning. I planned on just using these as a suffix to the job folder path after the program finds it.

      I know the asterisk won't create folders for me. The job folder's name looks something like this.
      "1121 Construction Company 165 Apple Rd, New York"
      So only the number assigned to the job at the beginning of the folder is a known value for all the workers who would use this.

      I have no idea what the bit in red does lol. That portion of code I have copied and pasted and used in a few small bat programs.

      Some things that I've changed since the last post are as follows. I saw a post of yours about copying a folder found with the asterisks so you can get it's name. Not sure if I worded that correctly but basically I think I need to find the job folder with

      Code: [Select]
      if exist "%drive%:\%jobNumber%*" (
      set temp=%drive%:\%jobNumber%*
      xcopy /t /e "%temp%" "C:\TEMP"
      )

      I keep getting cyclic copy error with that though so I've tried this a few ways like setting the variable temp. I'm only copying the folder and no files so I can later tell the program to look for a folder in the "NY SERVER" with the same name as the copied folder. Maybe I am completely headed in the wrong direction now.

      Sorry if this is lengthy but to sum it all up this is what I need the program to do. Find a folder on the "NY SERVER" based on it's first numbers. Then copy files to predetermined sub folders within that job folder.

      vvv FULL CODE SO FAR vvv
      Code: [Select]
      @echo off
      title Release A Job
      color a
      set drive=C
      set pathStart="%~dp0\job.zip"
      set pathEnd=0
      set pathEnd1="06. SHOP DRAWINGS"
      set pathEnd2="13. PRODUCTION ( In House)"
      set pathEnd3="15. INSTALLATION PACKAGE"

      :main
      cls
      echo.
      echo Enter the number of your choice and press "Enter"
      echo.
      echo (1) Enter
      echo (2) Change your NY Server Location (Current drive: "%drive%:\")
      echo (3) Exit
      set /p gateMain=
      if %gateMain% == 1 goto step1
      if %gateMain% == 2 goto drive
      if %gateMain% == 3 exit
      goto main

      :step1
      cls
      echo.
      echo Enter the job number only
      echo.
      set /p jobNumber=
      set jobFolderCheck=a

      set jobFolder=a

      if exist "%drive%:\%jobNumber%*" (
      goto success
      )
      goto fail

      :fail
      color c
      cls
      echo.
      echo THIS JOB DOES NOT EXIST
      echo.
      echo Make sure your computer has the NY Server Labeled in the %drive%:\ Drive
      echo If not you have to change this on the main menu (Option "2")
      echo.
      pause
      color a
      goto main

      :success
      cls
      echo.
      echo This job was found.
      echo No errors to this point
      echo.
      pause
      cls

      set temp=%drive%:\%jobNumber%*
      xcopy /t /e "%temp%" "C:\TEMP"

      set pathEnd="%drive%:\%jobNumber%*"
      "C:\Program Files\Winrar\WinRAR.exe" x %pathStart% %pathEnd%

      pause
      exit

      :drive
      cls
      echo What is the "NY Server's" letter on your computer.
      echo For example your main computer is likely labeled C
      echo.
      echo (Current drive: "%drive%:\")
      echo If this does not match your computer's label
      echo please enter the correct letter and press "Enter"
      echo.
      echo Enter "1" to go back to the main menu
      echo.
      set /p gateDrive=

      if exist "%gateDrive%:\" (
      set drive=%gateDrive%
      goto main
      )

      if %gateDrive% == 1 goto main
      goto drive


      JoshCM

        Topic Starter


        Greenhorn

        • Experience: Familiar
        • OS: Windows 10
        Re: Help with unknown path
        « Reply #3 on: June 27, 2018, 07:44:07 AM »
        If I don't get a cyclic copy error it copies the whole NY server not just the job folder. Any ideas why?
        By the way I keep calling it a server but it's really just a drive that is accessible through the company's network.

        Code: [Select]
        xcopy "%drive%:\%jobNumber%*" C:\TEMP /t /e