How copy file from subfolder to another, dir struct unknown

June 22, 2013 at 04:02:37
Specs: Windows XP
Okay here we go.
Usually it is not that hard to move a csv file from one subfolder to another subfolder in the same directory, BUT here's my challenge/question.

Only the subfolder (lowest level) containing the file and the folder one level up, are known.
The entire directory structure is unknown (for easier maintenance of all the batch files being used, but that's a whole new subject).

What batch command can/must I use to move the csv file from 00_Create_export_file to 04_Backup_file?

My folder structure (in Windows XP) is:
Source ?:\?\?\?\AccountNumber\00_Create_export_file
Target ?:\?\?\?\AccountNumber\04_Backup_file

Can you help me out?
Thanks!


See More: How copy file from subfolder to another, dir struct unknown

Report •


#1
June 22, 2013 at 10:19:14
Perhaps you'd like to explain why the directory structure is unknown?

How To Ask Questions The Smart Way


Report •

#2
June 22, 2013 at 12:19:22
Hello Razor,

The reason is that I have to transfer the \AccountNumber\Subfolders to application support. I don't know (yet) in what directory they will copy the batch file structure. So for the sake of being helpful I wanted to provide a solution that's independent of their choice.
Could a PATH or %~dp0 be an option? If so, how?

Thanks!


Report •

#3
June 22, 2013 at 17:46:58
Read up on working directories and relative paths. If the user starts the script from explorer, the working directory will be wherever the script lives. If the user starts the script from a shortcut, the working directory is specified by the "Starting in" field. The one exception is if the user starts the script from an unmapped network share.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
June 23, 2013 at 02:49:45
Will do Razor. Thanks for your response and directions!

Report •

#5
June 23, 2013 at 05:58:46
This is what works. The link offers other posibilities, but in the time I had, following was most usefull:

:: Copied from http://stackoverflow.com/questions/...
@echo off
setlocal

goto MAIN
::-----------------------------------------------
:: because entire path is unknown and only the current and parent folder are known,
:: use following function to work with those 2 (independent of rest of dir or location).
:: That way you can move a(ny) file from current working folder to another folder on same level.
:: "%~f2" get abs path of %~2.
::"%~fs2" get abs path with short names of %~2.
:setAbsPath
setlocal
set __absPath=%~f2
endlocal && set %1=%__absPath%
goto :eof
::-----------------------------------------------

:MAIN
call :setAbsPath ABS_PATH ..\
echo %ABS_PATH%

move %ABS_PATH%\00_Create_export_file\Export_account_numbers*.csv %ABS_PATH%\04_Backup_file\
endlocal


Report •

Ask Question