Script to match and move Files and associated folder

Hello!

     I need some help, I need to be able by scripting to match a file "name.ext " and a folder "name" the description on the "name" is the same on the file and the folder, after I checked that I have the file and the folder on the following path "z:\products" I need to move this to a x:\backup folder.

To be able to monitor the files that have been modev to x:\backup i need to set a number of time that the script checks the files and folders.

Is this possible by script?
LVL 1
elburgundi666Asked:
Who is Participating?
 
MSE-dwellsCommented:
If you run the following one-liner having cd'd to the directory your interested in scanning, does it do what you want -

for /f "tokens=*" %D in ('dir /a-d /b') do @if exist "%~dpnD\" @echo move "%~dpnxD" [your target file here] && @echo move "%~dpnD" [your target folder here]

... copy the line verbatim (note, it's a single line command -- there's no line break in there) and running it from a suitable directory.  It won't do anything at this point, removing the echo prefix and replacing the obvious references with your specific directory structure will enable it.  If you decide to add it to a batch file, you must double the % symbols -

for /f "tokens=*" %%D in ('dir /a-d /b') do @if exist "%%~dpnD\" @echo move "%%~dpnxD" [your target file here] && @echo move "%%~dpnD" [your target folder here]
0
 
MSE-dwellsCommented:
I'm having difficulty understanding what you want, can you give an example please.
0
 
elburgundi666Author Commented:
i.e. The folder x:\temp have several Subfolders and .DAT files that associated to the sub folder.
-temp
 -name1
 -name1.dat
 -name2
 - name2.dat
 - name3
 - name3.dat

What I'm looking for is to be able to match the "name1.dat" file  to the "name1" and if I have the two of them to move them in to a different folder.

What do you think?
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
MSE-dwellsCommented:
Is the name going to remain the same or similar or based on some known prefix or could it be anything at all?
0
 
elburgundi666Author Commented:
Hi!

   It can be anything, but it usually shows a 6 to 12 numbers on the name.

Thanks!
0
 
MSE-dwellsCommented:
So does the following adequately represent the required logic -

1. scan a given directory (not including its subdirectories) for all files
2. remove the extension from the filename and determine if a folder of that name exists in the same directory as the file
3. if so, move both the file and the folder to a different directory
0
 
elburgundi666Author Commented:
That's correct....
0
 
elburgundi666Author Commented:
Hello!

   How can we do this with all the files and folders on a specific folder?

Thanks!
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.