Jump to content

search on specific character in filename


Recommended Posts

You use FileMove() to rename files.

So you say, that I have to replace the filecopy function with the filemove function?

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

If StringInStr($file, "XS-32", 2) <> 0 Then; Search for your example text

FileCopy("C:\XS\" & $file, "H:\XS\KVA\" , 9); Move the file. Read the helpfile on this command. 9 = Create dirs and overwrite if exists!!

EndIf

Edited by joopgoudvis
Link to comment
Share on other sites

FileMove("H:\XS Dir\XS-32dasdada.xml","H:\XS Dir\XS-32.xml",9)

hope this can help

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

No. I said you use FileMove() to rename files. I really don't understand why you are still stuck on this, FileCopy($source, $destination).

If the original file is called "ABC" and you need it to be called "XYZ", you do FileCopy("ABC", "XYZ").

Link to comment
Share on other sites

Wouldn't that give problems? because I don't know the exact filename each time, I used FileFindFirst file, to pick 'XS-32'out of the filename to move the complete file., because the filename is huge.

$searchdir = "C:\XS\"; See use below here

; Shows the filenames of all files that are found.

$search = FileFindFirstFile($searchdir &"*XS-32*" ); Search in the $searchdir directory

; Check if the search was successful

If $search = -1 Then

MsgBox(0, "Error", "No files/directories matched the search pattern")

Exit

EndIf

While 1

$file = FileFindNextFile($search)

If @error Then ExitLoop

If StringInStr($file, "XS-32", 2) <> 0 Then; Search for your example text

FileCopy("C:\XS\" & $file, "H:\XS\KVA\" , 9); Move the file. Read the helpfile on this command. 9 = Create dirs and overwrite if exists!!

EndIf

;MsgBox(4096, "File:", $file); File that is found is displayed here

WEnd

; Close the search handle

FileClose($search)

Edited by joopgoudvis
Link to comment
Share on other sites

why don't you copy file from C:\ To H:\ with the new name , so you don't have to use FileMove()

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

*Slams his head against the wall* Oh my god! How could I be so STUPID!

Thank you very very very much!

last question about this subject:

I have several dirs where he needs to copy and search too, I could just copy-past the code a few times, but is there a proper way to achief it in code?

Example:

The logfiles are in one folder XS-1, XS-2,XS-3

XS-1 --> Folder1 on location A:

XS-2 --> Folder2 on location B:

Etc etc

Edited by joopgoudvis
Link to comment
Share on other sites

What I don't understand is why you are using FileFindFirstFile()...FileFindNextFile(). If there are multiple matches won't you be overwriting the same file in the destination???

Why can't this do everything you asked?:

$source = "C:\XS"

$destination = "H:\XS"

FileCopy($source & "\*XS-32*", $destination)

Link to comment
Share on other sites

Because i'm new too auto it and that command worked...*Shame on me*

And I need to copy a file, with a filename that is huge, and each time, the name is different, except for XS-32 in the filename.

And there are other files in that dir.

Yes, also they need to be copied, but too other folders, and with other filenames.

Edited by joopgoudvis
Link to comment
Share on other sites

Because i'm new too auto it and that command worked...*Shame on me*

are there any question ? what about the XS-1 and XS-2 and XS-3 ?

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

Because i'm new too auto it and that command worked...*Shame on me*

And I need to copy a file, with a filename that is huge, and each time, the name is different, except for XS-32 in the filename.

And there are other files in that dir.

Yes, also they need to be copied, but too other folders, and with other filenames.

Oh god.

FileCopy("C:\XS1\*XS-32*", "H:\XS1")

FileCopy("C:\XS2\*XS-32*", "H:\XS2")

FileCopy("C:\XS3\*XS-32*", "H:\XS3")

-or-

For $X = 1 to 3

FileCopy("C:\XS" & $X & "\*XS-32*", "H:\XS" & $X)

Next

Link to comment
Share on other sites

The best way to get help with that is, I think, to post here when what has to move where.

All we know now is that there has to be "XS-32" in the filename. These files are all in the same folder.

They have to move to a new location.

How do we know which location they have to move to?

So what rule is defining where a file has to go?

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...