Computing.Net > Forums > Programming > Move all the .csv files not in .txt

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Move all the .csv files not in .txt

Reply to Message Icon

Name: Rudresh
Date: July 28, 2008 at 02:50:05 Pacific
OS: win xp
CPU/Ram: intel
Product: 2006
Comment:

Hi All,

I have to write a batch script for the below scenario..Pls help me with a batch script..

In folder A i have lot of .csv files and some of these files are listed in a .txt via a bat script..based on their extension.

In the mean time some more .csv files are added in folder A...
Now i want to write a .bat script which has to move all the .csv files which are not listed in the .txt file to folder B...(i.e all the .csv files which are newly added these files are dynamically generated).

Please suggest how can i do this...

Thanks & Regards,
Rudresh



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 28, 2008 at 04:15:01 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /f "tokens=* delims= " %%a in ('my.txt') do (
attrib +h %%a
)
move *.csv B
attrib -h *.*


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: Rudresh
Date: July 28, 2008 at 05:52:39 Pacific
Reply:

Hi Mechanix,

Thanks for the response..

I think i have not made myself clear while posting...

I have two folder folder A and folder B

In folder A say i have 10 .csv files..based on their extensions i will make a list of these 10 files and send them to a .txt say myfile.txt...for my queue job which will process the files which are in myfile.txt....

now when the job is running i will get new source files in folder A say 20 new .csv files.., i have to write a batch script which has to move all the new files i.e the files which are not listed in myfile.txt to folder B.

so i that i can process my job parallerly with the newfiles.

Thanks & Regards,
Rudresh


0

Response Number 3
Name: rojanu
Date: July 28, 2008 at 06:00:51 Pacific
Reply:

Hi!

Mechanix2Go I had came up with the following solution but now it started to drive me mad as HITS is always set to 0.

Could you explain what am I doing wrong


@ECHO OFF
REM Create an up to date list of all files in A
DIR /s/b A\ > up2date.txt
REM Read up 2 date list in
SET HITS=0
SET NAME=nul
FOR /f %%U IN (up2date.txt) DO (
REM Read list in and check if file exists in list
FOR /f %%L IN (list.txt) DO (
SET NAME = %%~nU
IF NOT "A\%%~nU" == "A\%%~nL" (
ECHO HITTING
CALL :sub 1
)
)
REM NO HITS File is not in the list copy it over to B
ECHO HITS %HITS%
IF HITS == 0 (
MOVE A\%NAME% B\%NAME%
ECHO Moving %NAME%
)
)
GOTO eof

:sub
ECHO %1
SET HITS = %1
ECHO SUB HEAT: %HITS%
:eof
endLocal

THANKS


0

Response Number 4
Name: klint
Date: July 28, 2008 at 06:25:57 Pacific
Reply:

@rojanu,

I've just had a quick read of your post and can see a few errors:

1. "SET HITS=0" and "SET HITS = %1" refer to two different variables: "HITS" and "HITS ".

2. You are using %VAR% inside a loop, this will translate VAR to its value before the loop is entered and will have the same value throughout the loop. Use delayed expansion (i.e. !var! ) - for more details, type SETLOCAL/?.

3. You've got ENDLOCAL at the end, but no SETLOCAL, which you presumably intended to have. Probably not a major problem.


0

Response Number 5
Name: rojanu
Date: July 28, 2008 at 07:43:51 Pacific
Reply:

Thanks klint got it working now


@ECHO OFF
setLocal ENABLEDELAYEDEXPANSION
DIR /s/b A\ > up2date.txt
REM Read up 2 date list in
SET HITS=0
SET NAME=name.txt
FOR /f %%U IN (up2date.txt) DO (
FOR /f %%L IN (list.txt) DO (
SET NAME=%%~nxU
IF NOT "A\%%~nxU" == "A\%%~nxL" SET HITS=1
)
IF !HITS!==1 (
ECHO Moving !NAME!
MOVE A\!NAME! B\!NAME!
)
)
del up2date.txt
endLocal


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: July 28, 2008 at 07:48:09 Pacific
Reply:

klint hit the mark.

A space is a char, evn though it's hard to see.

No need to endlocal at the end. Local ends when the bat quits.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 7
Name: rojanu
Date: July 29, 2008 at 00:23:20 Pacific
Reply:

Mechanix, thanks for your input, by the way I liked your quick way of thinking in solution you have provided and it looks like that rudresh has not tried it

thanks again


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Move all the .csv files not in .txt

zip all the .csv files in a folder www.computing.net/answers/programming/zip-all-the-csv-files-in-a-folder/16724.html

Need to move all .txt and .csv file www.computing.net/answers/programming/need-to-move-all-txt-and-csv-file/16507.html

batch file help with csv files www.computing.net/answers/programming/batch-file-help-with-csv-files/17208.html