1

I have an application that generates a directory with some files in it when it is opened. I would like to access some files in this directory to export them and also import into this directory. The directory structure looks like this:

+ Folder I know
   + Auto Generated Folder         'Name changes every time
      -SomeFile
      -SomeFile2
      +macro
         -macro1
         -macro2
         -macro3

I want to work with just the files under the 'macro' sub directory. I have a working export solution using the 'for' command that looks at the 'Folder I know' and does a does a match:

 for /R "C:\Folder I know\" %f in ("macro*") do @xcopy "%f" "destination path" /u /y

The /u switch on the xcopy command even allows me to only update files that already exist in the destination. Now the question is, how do I do the same thing but in reverse? I want to copy files from a folder (say c:\temp) and update them in the macro folder only if they are already there.

1
  • Please explain what do you mean by "to export them and also import into this directory". Or consider rephrasing that part, it's kind of unclear what you are trying to achieve :) Jan 24, 2012 at 14:41

2 Answers 2

0

I'm not quite sure I understand exactly what it is you are trying to do, but it seems the %CD% environment variable could be of use. This variable keeps track of the current working directory, including drive letter and full path. Here's a screenshot of it in action.

enter image description here

Knowing that variable, you can use it in scripts to whatever degree you find it useful. In your particular case, it seems you might have to copy your script into the macro folder every time it's generated and run it from there.

The only way you could perhaps write a script that will work externally, is if you can get a hold of whatever variable the program creates to auto-generate the one folder name. Alternately, if the auto-generated folder name follows some sort of convention you could match to a pattern, there are probably some options involving IF statements, RegExes, and string commands that could work for you.

0

After some more thought and testing, I found a solution.

FOR /R "C:\Folder I know\" %f IN ("*") DO @xcopy "network path\%~nf" "%~pf" /e /u /y

The for command still only looks at each file in the folder I know, including the sub directories I don't know. It then does an xcopy using the network path where the files are backed up. The %~nf appended to the end gets the file name of the current file from the for command. It then copies it to the local folder using the %~pf which gets the path of the current file from the for command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .